windows下安裝nginx與配置 安裝
在 nginx 官網(wǎng)下載頁(yè)面下載最新的包 http://nginx.org/en/download.html,目前最新的版本是1.13.3, window系統(tǒng)選擇 nginx/windows-1.13.3 下載。
下載完成之后解壓到c盤,并進(jìn)入到該目錄 c:nginx-1.13.3, 雙擊運(yùn)行 nginx.exe 文件;(啟動(dòng)的時(shí)候會(huì)有一個(gè)窗口閃一下,這是正常情況)
然后打開瀏覽器訪問 http://localhost/ , 如果頁(yè)面上顯示 welcome to nginx!, 那么恭喜,到這一步已經(jīng)成功了!
配置
接下來我們開始配置 nginx, 配置文件是 c:nginx-1.13.3confnginx.conf;
配置文件的代碼結(jié)構(gòu)是:
http{ include mime.types; default_type application/octet-stream; server { listen 80; server_name localhost; } #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; # } #} }
每個(gè) server 都分別是一個(gè)站點(diǎn)。
listen 端口號(hào) server_name 域名 root 站點(diǎn)根目錄(路徑必須使用\\\’/\\\’, 不能使用反斜杠 ) index 默認(rèn)首頁(yè) 例子
比如我有一個(gè)網(wǎng)站放在d盤(跨磁盤那是很簡(jiǎn)單的事),那么配置文件就這樣配置:
server { listen 80; server_name www.test.com; location / { root d:/nginx_www/test; index index.html index.htm; } }
當(dāng)然也肯定是需要修改hosts文件的,里面增加一行配置:
127.0.0.1 www.test1.com
前面已經(jīng)開啟了nginx服務(wù),需要重啟一下;關(guān)于如何重啟,請(qǐng)看下面段落。
然后就可以打開瀏覽器訪問 www.test1.com站點(diǎn)了;
nginx常用相關(guān)命令
這些命令都需要在 c:nginx-1.13.3 目錄下面執(zhí)行
啟動(dòng) start nginx 重啟 nginx -s reload 強(qiáng)制關(guān)閉 nginx -s stop 安全關(guān)閉 nginx -s quit
如果覺得每次輸入這些命令比較麻煩,可以將命令保存到.bat文件里面,以后雙擊執(zhí)行即可。