Hallo zusammen, ich habe eine Frage
Problembeschreibung:
location ^~ /tomcat/ {
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^~ /ife2017/ {
proxy_pass http://127.0.0.1:8080/ife2017/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Das Obige ist Teil meiner Nginx-Konfiguration, der Zweck ist
1. Leiten Sie alle Anfragen von www.abc.com/tomcat/xxx an Tomcat weiter, die Funktion ist normal
2. Springen Sie alle Anfragen von www.abc.com/ife2017/xxx zu Tomcat und dann über Tomcat zu ife2017. Die Funktion ist nicht normal
Hinweis: ife2017 ist ein Ordner im Stammverzeichnis von Tomcat, auf den vor der Verwendung des Nginx-Proxys normal zugegriffen werden kannDie spezifische Leistung besteht darin, dass www.abc.com/ife2017/123 ohne Portnummer normal springen kann
Aber www.abc.com/ife2017/123/456 kann nicht normal springen und springt zu www.127.0 .0.1.com /ife2017/123/456
Vielen Dank an alle im Voraus
反向代理配置的問題,tomcat
并不知道他在nginx
后面,所以發(fā)送的重定向響應(yīng)頭仍然是使用后端的地址。在apache
中可以通過配置ProxyPassReverse
選項(xiàng)修改后端發(fā)給client
的響應(yīng)頭來實(shí)現(xiàn),在nginx
中沒有類似選項(xiàng),所以在發(fā)給后端的請求中添加代理信息來實(shí)現(xiàn)(告訴tomcat前面有代理):
server {
listen myhost:80;
server_name myhost;
location / {
root /path/to/myapp/public;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://myapp:8080;
}
}
參考文檔:NGINX Solution for Apache ProxyPassReverse