Glassfish 和 Nginx:2 个不同位置的 2 个应用程序

Glassfish and Nginx: 2 apps in 2 different locations

本人是nginx新手,如有错误请多多包涵

域名:http://www.example.com

2 个 glassfish 应用程序:

http://localhost:8080/app1
http://localhost:8080/app2

我想要什么:

Glassfish 应用程序 1 服务于: http://www.example.com

Glassfish app2 服务于: http://www.example.com/app2

目前我有:

server {
    listen       80;
   server_name  example.com www.example.com;

    location / {
        proxy_pass      http://localhost:8080/app1/;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_pass_header Set-Cookie;
        proxy_pass_header X-Forwarded-For;
        proxy_pass_header Host;    }

    location /app2/ {

        proxy_pass      http://localhost:8080/app2/;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_pass_header Set-Cookie;
        proxy_pass_header X-Forwarded-For;
        proxy_pass_header Host;    }
}

但是路径搞混了:当我执行“http://example.com/app2" this is "http://example.com/app1”时出现了。

帮忙?

这可能是一个重定向问题,单独 nginx 可能无法解决。

应用程序经常向其控制器发出重定向,如果 app2 认为它在根目录中,它可能会向 / 发出重定向,该重定向将立即转发给 app1。

您需要查看重定向 headers 并确定是否可以将 proxy_redirect 放入位置容器以解决问题。

您还需要考虑app1和app2是否可以在子目录中运行。例如,他们访问 CSS 和 JS 文件时使用的是相对路径还是绝对路径。 nginx.

无法更正这些引用