初探wnmp php

wnmp是windows下,Nginx、MySQL、PHP的環(huán)境集成包。新手用該集成包學(xué)習(xí)PHP,搭建自己的本地服務(wù)器十分便利。原理性的東西我還需要進(jìn)一步學(xué)習(xí),現(xiàn)在先簡單看一下如何完成初始的環(huán)境構(gòu)建。
首先進(jìn)行本地服務(wù)器地址路徑設(shè)置:
打開安裝目錄下的conf文件,在其中找到nginx.conf。初始配置文件如下:

worker_processes  1;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    # Max value 16384
    worker_connections  8192;
    # Accept multiple connections
    multi_accept on;
}

# Settings that affect all server blocks
http {
    include php_processes.conf;
    include       mime.types;
    default_type  application/octet-stream;

    access_log  logs/access.log;

    sendfile on;
    
    keepalive_timeout  65;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS; 
    ssl_prefer_server_ciphers on;
    gzip  on;
    # http server

# Begin HTTP Server
server {
    listen 80; # IPv4
    server_name localhost;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }
        
    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location

} 
# End HTTP Server

# Begin HTTPS Server
server {
    listen 443 http2 ssl;
    server_name localhost;
    ssl_certificate      cert.pem;
    ssl_certificate_key  key.pem;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }

    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files are served directly.
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location
} # End HTTPS Server
}

改變http和https中的root下的路徑為你所需要搭建本地服務(wù)器的路徑,默認(rèn)為html即可,其它內(nèi)容還得繼續(xù)研究,先跑起來再說~

此時,打開wnmp,start all之后,在瀏覽器輸入localhost,看到這個頁面,就代表已經(jīng)安裝成功:

然后,自己嘗試搭建第一個網(wǎng)頁:

1、簡單描述下web 服務(wù)器、PHP、數(shù)據(jù)庫、瀏覽器是如何實現(xiàn)動態(tài)網(wǎng)站的?

要了解動態(tài)網(wǎng)站,首先我們得知道一個用戶獲取靜態(tài)網(wǎng)頁的過程:

  • 首先用戶在瀏覽器輸入URL后,通過DNS來獲取IP地址以找到相對應(yīng)服務(wù)器。
  • 服務(wù)器根據(jù)用戶的需求,即URL地址上所表達(dá)的東西,返回給瀏覽器一個靜態(tài)的HTML文件。
  • 最后瀏覽器對該HTML文件進(jìn)行渲染展現(xiàn)給用戶。

如果網(wǎng)頁是一成不變的還好,但是涉及到表單提交時,靜態(tài)網(wǎng)站就遠(yuǎn)不能滿足用戶的需求了:


在靜態(tài)網(wǎng)頁,用戶表單填寫無法與服務(wù)器進(jìn)行交互,只能將數(shù)據(jù)填寫完成之后,以郵件發(fā)送的形式將數(shù)據(jù)提交,且無法檢查自己填寫的信息,這么麻煩的操作催生了動態(tài)網(wǎng)頁的形成。

  • 首先用戶按照靜態(tài)頁面的方式獲取了一個頁面;
  • 當(dāng)用戶在該靜態(tài)頁面上發(fā)送請求時,向服務(wù)器提交了一個php腳本的地址;
  • 服務(wù)器通過php對用戶的需求進(jìn)行處理:可以發(fā)送郵件,也可以通過數(shù)據(jù)庫(php一般對應(yīng)的MySQL)增刪改查來存儲數(shù)據(jù);
  • 服務(wù)器將運行過php轉(zhuǎn)換為html文件,并返還給瀏覽器;
  • 瀏覽器對html文件進(jìn)行渲染,呈現(xiàn)在用戶面前。

2、常見的web服務(wù)器有哪些?

最常見的WEB服務(wù)器是:Apache、Nginx、IIS;
此外還有:Tomcat和Zeus。

3、打開瀏覽器,在地址欄輸入 http://jirengu.com 頁面展現(xiàn)了饑人谷官網(wǎng)的信息,整個過程發(fā)生了什么?(饑人谷官網(wǎng)后臺語言 php,web服務(wù)器 nginx,數(shù)據(jù)庫 mysql)

  • 首先在瀏覽器輸入了URL地址(http://jirengu.com](http://jirengu.com/)
  • 互聯(lián)網(wǎng)通過DNS將URL翻譯成IP地址(如果先前訪問過該網(wǎng)站,通過瀏覽器->操作系統(tǒng)->路由器->運營商->根,層層尋找DNS緩存,一定會得到!);
  • 若用戶以前登錄過饑人谷官網(wǎng),隨著URL地址傳過來的還有一個cookie。
  • 此饑人谷的服務(wù)器nginx得到響應(yīng),根據(jù)用戶的需求,通過PHP進(jìn)行處理,如果涉及到用戶登錄以及數(shù)據(jù)請求或提交,還將與數(shù)據(jù)庫MySQL進(jìn)行交互,服務(wù)器將返回一個靜態(tài)的html文檔。
  • 通過TCP/IP協(xié)議三次握手,確定網(wǎng)絡(luò)正常,將靜態(tài)html文檔送至客戶端(瀏覽器)。
  • 瀏覽器對html進(jìn)行渲染,將饑人谷官網(wǎng)呈現(xiàn)給用戶。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,991評論 19 139
  • 第一章 Nginx簡介 Nginx是什么 沒有聽過Nginx?那么一定聽過它的“同行”Apache吧!Ngi...
    JokerW閱讀 32,803評論 24 1,002
  • 每逢春節(jié),一票難求,很多老哥都會選擇自駕回鄉(xiāng)過年。小編在這里提前和大家分享一些冬季長途駕車的安全小常識。 1.防范...
    五哥說車閱讀 391評論 0 0
  • 周五參加了頭馬資深資深大咖同時也是TDB創(chuàng)始人郭老師進(jìn)行的一場面試培訓(xùn),干貨滿滿、收獲很多,與大家一起分享希望共同...
    batheny閱讀 3,049評論 2 3