- nginx (windows啓動)
啓動nginx:start nginx nginx
中止nginx: nginx -s stop nginx -s quit
從新載入 nginx:nginx -s reload
從新打開日誌文件:nginx -s reopen
查看nginx -v:運行nginx -V能夠查看該Win32平臺編譯版支持哪些模塊
nginx: [error] open() " E:\nginx\nginx\nginx-1.10.2\logs\nginx.pid" failed (2: No such file or directory)
解決方式:啓動nginx 改成指定配置文件路徑:nginx -c E:\nginx\nginx\nginx-1.10.2\conf\nginx.conf
- nginx(反向代理配置)
http {
...
#設定負載均衡的服務器列表
#weigth參數表示權值,權值越高被分配到的概率越大(可配置多臺服務器,自動分配代理到哪臺服務器)
upstream 192.168.0.22{
server 192.168.0.27:8080 weight=1;
...
}
#upstream server{
# server 192.168.0.27:8080 weight=1;
#}
server {
listen 80; #端口號
server_name localhost;
location / {
proxy_pass http://192.168.0.22;
#proxy_pass http://server;
#root html;
#index index.html index.htm;
}
...
}
...
}
若是反向代理的頁面有靜態資源連接,IP會被替換爲服務列表名
例:原靜態資源地址: http://192.168.0.27:8080/Esell/css/style.css 會替換爲:
http://192.168.0.22:22:80/Esell/css/style.css
使用第二個屏蔽配置:http://192.168.0.27:8080/Esell/css/style.css 會替換爲:
http://server:80/Esell/css/style.css
- 配置說明
默認靜態頁面路徑在安裝程序下html,若是要從新配置錄入全路徑
- Nignx註冊Windows服務
下載 windows service wrapper;
拷貝winsw-1.8-bin.exe 到nginx主目錄,修改程序名爲myapp.exe,建立配置文件myapp.xml:
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>D:\nginx-1.10.2\nginx.exe</executable>
<logpath>D:\nginx-1.10.2\logs</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p D:\nginx-1.10.2</startargument>
<stopargument>-p D:\nginx-1.10.2 -s stop</stopargument>
</service>
安裝服務:cd /d D:\nginx-1.10.2\; myapp.exe install,服務被註冊到Windows服務