nginx代理到Tomcat(不是ROOT)应用程序

时间:2017-12-17 18:25:18

标签: java tomcat nginx proxy

我遇到了与nginx连接的问题。情况就是这样:我让Tomcat在localhost:8080上运行,这很好并且设置好了。在那个tomcat上,我有2个应用程序分别在路径/app-test/app-prod运行。

我有2个子域,比如test.mydomain.comprod.mydomain.com,我希望这些子域代理到各自的tomcat应用程序。换句话说,当我的用户键入:test.mydomain.com/some/resource时,我希望将该请求代理到localhost:8080/app-test/some/resource等。根据教程,这应该可以正常工作,但它不会。

例如,当我转到test.mydomain.com时,它会将我重定向到获得test.mydomain.com/app-test/login的{​​{1}}(请注意,有一个spring应用程序,会重定向到404 URI )。这里所需的行为是将我重定向到/login。我怎么能做到这一点?我发现了这个thread,但这似乎是hacky而不是很优雅。

到目前为止我在conf中得到了什么:

test.mydomain.com/login

所以,我的问题是,是否有更优雅的解决方案,来自serverfault线程。谢谢你的任何想法!

编辑:重写解决方案的问题在于它允许用户查看我的堆栈的内部结构,我的意思是,它将它们重定向到upstream tomcat_server { server 127.0.0.1:8080 fail_timeout=0; } server { listen 80; server_name prod.mydomain.com; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_redirect off; proxy_connect_timeout 240; proxy_send_timeout 240; proxy_read_timeout 240; # note, there is not SSL here! plain HTTP is used proxy_pass http://tomcat_server/app-prod/; } listen 443 ssl; # managed by Certbot ssl_certificate ... ssl_certificate_key ... include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot if ($scheme != "https") { return 301 https://$host$request_uri; } # managed by Certbot } server { listen 80; server_name test.mydomain.com; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_redirect off; proxy_connect_timeout 240; proxy_send_timeout 240; proxy_read_timeout 240; # note, there is not SSL here! plain HTTP is used proxy_pass http://tomcat_server/app-test/; } listen 443 ssl; # managed by Certbot ssl_certificate ... ssl_certificate_key ... include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot if ($scheme != "https") { return 301 https://$host$request_uri; } # managed by Certbot } ,我认为可能是安全风险。

0 个答案:

没有答案