Windows下 Nginx安裝與配置
一、下載
過程省略
二、配置
首先進(jìn)入nginx安裝目錄(nginx.exe同級(jí)),編輯conf/nginx.conf文件
gzip on; #開啟gzip
server_tokens off; ##隱藏nginx版本號(hào)
server {
listen 8888;
server_name localhost;
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist/;
index index.html index.htm;
}
location /oms {
proxy_pass http:ip:port; #目標(biāo)服務(wù)器
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
}
#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;
}
三、常規(guī)啟動(dòng):
這里可以先不采用此方式,稍后介紹設(shè)置開機(jī)自啟,將nginx納入系統(tǒng)服務(wù)后,通過系統(tǒng)命令管理
-
start nginx啟動(dòng) -
nginx -s stop快速停止nginx -
nginx -s quit完整有序的停止nginx -
nginx -s reopen重新打開日志文件 -
nginx -s reload重新加載配置
四、設(shè)置開機(jī)自啟:
推薦使用Windows Service Wrapper工具來安裝自啟動(dòng)服務(wù):
1.下載WinSW.NET4.exe;(如果服務(wù)器未安裝.NET Framework 4.0,請(qǐng)下載 WinSW.NET2.exe)
2.將WinSW.NET4.exe拷貝到nginx.exe相同目錄下,并重命名為nginxd.exe;
3.在nginxd.exe相同目錄下新建一個(gè)nginxd.xml的配置文件,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>D:\softs\nginx-1.14.0\nginx.exe</executable>
<startargument>-p</startargument>
<startargument>D:\softs\nginx-1.14.0</startargument>
<logpath>D:\softs\nginx-1.14.0/logs</logpath>
<logmode>roll</logmode>
<stopexecutable>D:\softs\nginx-1.14.0\nginx.exe</stopexecutable>
<stopargument>-p</stopargument>
<stopargument>D:\softs\nginx-1.14.0</stopargument>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument>
<stoptimeout>6sec</stoptimeout>
</service>
4.執(zhí)行nginxd.exe install 注冊(cè)服務(wù)
winsw相關(guān)命令:
installto install the service to Windows Service Controller. This command requires some preliminary steps described in the Installation Guide.uninstallto uninstall the service. The opposite operation of above.startto start the service. The service must have already been installed.stopto stop the service.restartto restart the service. If the service is not currently running, this command acts like start.statusto check the current status of the service.
This command prints one line to the console.
NonExistent indicates the service is not currently installed
Started to indicate the service is currently running
Stopped to indicate that the service is installed but not currently running.
5.通過windows系統(tǒng)NET命令啟動(dòng)
net start nginx 啟動(dòng)
net stop nginx 停止
net相關(guān)命令:
NET
[ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
STATISTICS | STOP | TIME | USE | USER | VIEW ]
以上。