我正在嘗試將所有流量從 www.impactteachers.com/teach 重定向到 application.impactteachers/teach。
這樣,我們的申請表也可以從以下 URL 存取:www.impactteachers.com/teach/
這在我們目前的 apache 伺服器上運作良好,規則如下:
ProxyRequests Off
ProxyPreserveHost On
<Proxy http://application.impactteachers.com:8080/teach/>
Order allow,deny
Allow from all
</Proxy>
ProxyPass /teach/ http://application.impactteachers.com:8080/teach/
ProxyPassReverse /teach/ http://application.impactteachers.com:8080/teach/
因為我們要將網站遷移到 Nginx 伺服器,所以我們需要建立一個新規則,根據本文:Apache ProxyPassReverse 的 Nginx 解決方案到目前為止,在您的幫助下,這是當前的程式碼:
location /teach {
proxy_set_header Host $host;
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;
proxy_pass http://application.impactteachers.com:8080/teach;
proxy_redirect default;
}
我已經測試過了,它仍然顯示相同的 404 錯誤。
答案1
試試這樣的事情:
upstream teach_backend {
server application.impactteachers.com:8080 fail_timeout=2s;
keepalive 32;
}
server {
listen 80;
server_name your_server_name.com;
location /teach {
proxy_http_version 1.1;
proxy_set_header Connection "";
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;
proxy_set_header Host $host;
proxy_pass http://teach_backend/teach;
proxy_redirect http://teach_backend/teach /teach;
#proxy_redirect default;
#expires -1;
#add_header Cache-Control "private";
}
}