Windows下 Nginx安裝與配置
一雾棺、下載
過程省略
二、配置
首先進(jìn)入nginx安裝目錄(nginx.exe同級)哑了,編輯conf/nginx.conf文件
gzip on; #開啟gzip
server_tokens off; ##隱藏nginx版本號
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ī)啟動:
這里可以先不采用此方式,稍后介紹設(shè)置開機自啟目溉,將nginx納入系統(tǒng)服務(wù)后,通過系統(tǒng)命令管理
-
start nginx
啟動 -
nginx -s stop
快速停止nginx -
nginx -s quit
完整有序的停止nginx -
nginx -s reopen
重新打開日志文件 -
nginx -s reload
重新加載配置
四明肮、設(shè)置開機自啟:
推薦使用Windows Service Wrapper工具來安裝自啟動服務(wù):
1.下載WinSW.NET4.exe;(如果服務(wù)器未安裝.NET Framework 4.0,請下載 WinSW.NET2.exe)
2.將WinSW.NET4.exe拷貝到nginx.exe相同目錄下,并重命名為nginxd.exe;
3.在nginxd.exe相同目錄下新建一個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
注冊服務(wù)
winsw相關(guān)命令:
install
to install the service to Windows Service Controller. This command requires some preliminary steps described in the Installation Guide.uninstall
to uninstall the service. The opposite operation of above.start
to start the service. The service must have already been installed.stop
to stop the service.restart
to restart the service. If the service is not currently running, this command acts like start.status
to 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命令啟動
net start nginx
啟動
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 ]
以上柿估。