wnmp是windows下,Nginx、MySQL、PHP的環(huán)境集成包。新手用該集成包學習PHP,搭建自己的本地服務器十分便利。原理性的東西我還需要進一步學習,現(xiàn)在先簡單看一下如何完成初始的環(huán)境構(gòu)建。
首先進行本地服務器地址路徑設置:
打開安裝目錄下的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下的路徑為你所需要搭建本地服務器的路徑,默認為html即可,其它內(nèi)容還得繼續(xù)研究,先跑起來再說~
此時,打開wnmp,start all之后,在瀏覽器輸入localhost,看到這個頁面,就代表已經(jīng)安裝成功:
然后,自己嘗試搭建第一個網(wǎng)頁:
1、簡單描述下web 服務器、PHP、數(shù)據(jù)庫、瀏覽器是如何實現(xiàn)動態(tài)網(wǎng)站的?
要了解動態(tài)網(wǎng)站,首先我們得知道一個用戶獲取靜態(tài)網(wǎng)頁的過程:
- 首先用戶在瀏覽器輸入URL后,通過DNS來獲取IP地址以找到相對應服務器。
- 服務器根據(jù)用戶的需求,即URL地址上所表達的東西,返回給瀏覽器一個靜態(tài)的HTML文件。
- 最后瀏覽器對該HTML文件進行渲染展現(xiàn)給用戶。
如果網(wǎng)頁是一成不變的還好,但是涉及到表單提交時,靜態(tài)網(wǎng)站就遠不能滿足用戶的需求了:
在靜態(tài)網(wǎng)頁,用戶表單填寫無法與服務器進行交互,只能將數(shù)據(jù)填寫完成之后,以郵件發(fā)送的形式將數(shù)據(jù)提交,且無法檢查自己填寫的信息,這么麻煩的操作催生了動態(tài)網(wǎng)頁的形成。
- 首先用戶按照靜態(tài)頁面的方式獲取了一個頁面;
- 當用戶在該靜態(tài)頁面上發(fā)送請求時,向服務器提交了一個php腳本的地址;
- 服務器通過php對用戶的需求進行處理:可以發(fā)送郵件,也可以通過數(shù)據(jù)庫(php一般對應的MySQL)增刪改查來存儲數(shù)據(jù);
- 服務器將運行過php轉(zhuǎn)換為html文件,并返還給瀏覽器;
- 瀏覽器對html文件進行渲染,呈現(xiàn)在用戶面前。
2、常見的web服務器有哪些?
最常見的WEB服務器是:Apache、Nginx、IIS;
此外還有:Tomcat和Zeus。
3、打開瀏覽器,在地址欄輸入 http://jirengu.com 頁面展現(xiàn)了饑人谷官網(wǎng)的信息,整個過程發(fā)生了什么?(饑人谷官網(wǎng)后臺語言 php,web服務器 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。
- 此饑人谷的服務器nginx得到響應,根據(jù)用戶的需求,通過PHP進行處理,如果涉及到用戶登錄以及數(shù)據(jù)請求或提交,還將與數(shù)據(jù)庫MySQL進行交互,服務器將返回一個靜態(tài)的html文檔。
- 通過TCP/IP協(xié)議三次握手,確定網(wǎng)絡正常,將靜態(tài)html文檔送至客戶端(瀏覽器)。
- 瀏覽器對html進行渲染,將饑人谷官網(wǎng)呈現(xiàn)給用戶。