- 第一種(訪問IP轉發到IP+端口)
server{ listen 9003; server_name 192.168.1.114; index index.php index.html index.htm; location / { proxy_pass http://127.0.0.1:9002; } }
當訪問192.168.1.114:9003 的時候, 就會轉發到192.168.1.114的9002端口, 9002端口我配置的是PHPinfo(); 所以最終會顯示PHPinfo的信息.
- 第二種(訪問域名轉發到IP+端口去)
server{ listen 80; server_name www.test1.top; index index.php index.html index.htm; location / { proxy_pass http://127.0.0.1; } } #這里有個奇怪的問題, 域名我使用test1.top就403, 完全搞不懂為什么, 加上www 就正常了, 有待解決
訪問www.test1.top 轉發到192.168.1.114默認的nginx顯示的頁面, 同樣可以加上端口比如: http://127.0.0.1:9002; 就跳轉到PHPinfo頁面
- 第三種(訪問IP轉發到域名)
server{ listen 9003; server_name 192.168.1.114; index index.php index.html index.htm; location / { proxy_pass http://www.rubbish.top; } }
#這種是配置文件直接報錯, "host not found in upstream 'www.rubbish.top in ...'"更新嘗試了一下轉發到www.baidu.com, 是可以的, 那么應該就是轉發的域名必須是外網能訪問到才行. 所以配置文件才會報錯
- 第四種(訪問域名轉發到域名)
server{ listen 80; server_name www.test1.top; index index.php index.html index.htm; location / { proxy_pass http://www.baidu.com; } }
訪問www.test1.top跳轉到百度.
- proxy_pass 配置的路徑后面加 / 和 不加 / 的區別 : https://blog.csdn.net/ainuser/article/details/80260144
- 配置nginx的proxy_pass訪問rubbish.test.com轉發到quick.test.com, nginx的proxy_pass之所以會丟失post參數, 現在看來應該是因為轉發給了外部url, 而不是內部轉發, 內部轉發的時候, 並沒有丟失?
