參考: https://blog.csdn.net/csdn1152789046/article/details/51362735
修改前
項目放在Tomcat的webapps/ROOT/ 目錄下面
http://IP 直接訪問
location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; #Web服務器可以通過X-Forwarded-For獲取用戶真實IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #以上三行,目的是將代理服務器收到的用戶的信息傳到真實服務器上 proxy_pass http://127.0.0.1:8080; }
修改后
項目(mall) 放在webapps/ 目錄下面 移除原來webapps/ROOT/目錄內的文件
http://IP/mall 訪問
location /mall { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; #Web服務器可以通過X-Forwarded-For獲取用戶真實IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #以上三行,目的是將代理服務器收到的用戶的信息傳到真實服務器上 proxy_pass http://127.0.0.1:8080/mall;
#proxy_redirect 不加 出現js.css訪問404錯誤, 這里意思是
http://$hots(127.0.0.1):$server_port(80) 替換 http://127.0.0.1:8080 這樣js,css就能訪問了
proxy_redirect http://127.0.0.1:8080 http://$host:$server_port; }