【樂優商城】Nginx安裝配置 -反向代理實現埠轉換
阿新 • • 發佈:2018-11-05
一、bind() to 0.0.0.0:80 failed
原因:
是由於Windows10系統預設把80埠給佔用了,而nginx的埠也是80,所以說報錯。
2018/10/27 05:40:15 [emerg] 21724#22312: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions) 2018/10/27 05:41:54 [emerg] 15196#14864: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
解決:
1、執行中輸入regedit進入登錄檔;
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP
找到start,原本是3,我這裡改成了4.確認之後重啟系統。
二、CreateFile() "D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid" failed (2: The system cannot find the file specified)
正常情況下D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid,logs目錄下會有nginx.pid檔案,也有可能該目錄下沒有這個檔案。如果沒有,建立一個空檔案。參考: windows系統nginx重啟發生異常The system cannot find the file specified
2018/10/27 05:44:47 [error] 7336#12764: CreateFile() "D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid" failed (2: The system cannot find the file specified)
三、Nginx命令
-
啟動:
start nginx.exe
-
停止:
nginx.exe -s stop
-
重新載入:
nginx.exe -s reload
四、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;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name manage.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:9001;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
server {
listen 80;
server_name api.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:10010;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
}
五、start nginx.exe啟動命令
六、web專案路徑是localhost:9001
瀏覽器輸入命令:localhost:9001
ps:如果每次都去改host檔案的話,比較麻煩,當然也可以實現。這裡推薦使用SwitchHosts。
點選ok之後,再去瀏覽器輸入域名即可訪問了。