Nginx的是重定向到本地主机:8080 USERLOGIN网站
问题描述:
我使用nginx的服务器和Tomcat的,经过我公司采用以下配置Nginx的是重定向到本地主机:8080 USERLOGIN网站
server {
listen 80;
root /opt/tomcat/webapps/ROOT;
server_name ssss.com;
server_name_in_redirect off;
access_log /var/log/nginx/sss/site_access.log;
error_log /var/log/nginx/sss/site_error.log debug;
location/{
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_cookie_path ~*^/.* /;
proxy_pass http://localhost:8080;
}
}
我的问题是AFTR用户(给用户名和密码)登录过程我的网址正在播放localhost:8080/Home。
这里首页是正确的,但insted localhost:8080应该是我的网站名称。
如何解决这个问题。
答
我假设你的web应用程序在localhost:8080上的tomcat上运行。所以你要找的是在运行的tomcat实例之前使用nginx作为代理。我在这里的linux开发盒上进行了一个绝对最小配置的小测试。您可以使用以下配置nginx的:
server {
listen 80;
location/{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Fix the "It appears that your reverse proxy set up is broken" error.
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;
}
}
请注意,这不是在生产中使用!
请考虑例如nginx webpage关于如何保护你的nginx配置/代理设置。
尝试'proxy_set_header主机$主机;' –
我应该删除'proxy_set_header X-Forwarded-Host $ host;' – xrcwrn
@AlexeyTen感谢这很完美 – xrcwrn