Nginx Proxy for PlayFramework 从端口到路径前缀

Nginx Proxy for PlayFramework from port to path prefix

我有一个 Play 应用程序在本地端口 :9000 上侦听。还有其他应用程序 运行。 我想在如下路径提供此应用程序:

http://myhost/this-play-app -> localhost:9000

以便其他应用程序可以嵌套在其他路径。

我已经尝试了基本的 proxy_pass 但它似乎不起作用。

server {
    listen   80;
    server_name myhost;
    # MMC Tool
    # ----------------------------------------------------
    location /this-play-app {
        proxy_pass http://localhost:9000;
    }
}

播放应用程序似乎转发到根目录。有没有办法让播放应用程序在 /this-play-app 路径内工作?
喜欢 /this-play-app/some-controller 而不是 /some-controller ?

谢谢

在文件夹中使用应用程序不是一个好主意 - 您至少需要准备一些专用配置并在每次更改位置时更改它。

与其他人建议的相反,您应该使用子域,在这种情况下,每个应用的行为与在根域中的行为完全相同,即使您 need/want 更改该域,您也只需要更改在 nginx 的配置中。

nginx 的典型配置如下

upstream your_app {
    server 127.0.0.1:9000;
}

server {
    listen      80;
    server_name your-app.domain.com;
    location / {
      proxy_pass  http://your_app;
    }
}

很可能在某些 VPS 或共享主机上,您需要通过某种管理面板添加子域 - 在本地主机上只需将子域添加到 hosts 文件。

编辑 如果无论如何都无法使用子域(遗憾),您无论如何都可以通过配置解决它,在 nginx 中使用(正如您在问题中所做的那样:

...
    location /this-play-app {
        proxy_pass http://your_app;
    }
...

然后将此行添加到您的 application.conf(播放 2.1+)

application.context = "/this-play-app"

或者如果是 Play 2.4+ (info)

play.http.context = "/this-play-app"