由於開發需要,我們總是需要先在windows環境下面部署項目進行測試,通過之后才會移植到linux系統進行測試部署。
本篇文章會介紹一下windows終端下面部署nginx WEB服務的一些步驟流程,僅供參考!
一、nginx for windows源碼包下載:
http://nginx.org/download/nginx-1.9.9.zip #作者在部署的時候最新的版本是1.9.9
二、安裝
由於nginx采用的是一種開包即用的模式,所以直接解壓縮nginx-1.9.9.zip,然后將獲得的nginx-1.9.9文件目錄直接放到自己的安裝路徑。本人存放的路徑為:D:\Program Files\nginx-1.9.9
然后設置系統的環境變量:
1.新建nginx的變量名及指向路徑
2.添加nginx的變量環境到系統的總環境:
最后應用退出,這樣在系統的環境中就可以查看到nginx的環境變量:
三、配置
配置文件在conf目錄下面:

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; autoindex on; autoindex_exact_size off; autoindex_localtime off; # 顯示本機時間而非 GMT 時間 gzip on; gzip_comp_level 7; gzip_min_length 1024; gzip_buffers 4 8k; gzip_types text/plain application/javascript text/css ; output_buffers 1 32k; postpone_output 1460; server { listen 8080; server_name localhost; #charset koi8-r; charset gbk,utf8; #access_log logs/host.access.log main; location /soft/ { root E:\soft; index index.html index.htm; } location /ckfinder/ { root D:\webproject\ckfinder; index ckfinder.html; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /phpmyadmin/ { root D:\webproject\phpMyAdmin; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
備注:因為windows使用的gbk格式的文件編碼,而Linux系統中支持中文的編碼則是utf-8.所以為了在windows下面支持文件名中文的正常顯示,在http或server段添加下面的代碼參數:
charset gbk,utf8; #注意先后順序
四、nginx使用命令(CMD控制台下命令)
1.nginx啟動:
start nginx
2.nginx重啟:
nginx -s reload
3.nginx關閉
nginx -s stop #快速關閉
nginx -s quit #正常關閉
4.日志文件切割
nginx -s reopen #重啟日志文件,即對日志文件進行切割