![在 nginx 中的子路径中配置应用程序](https://linux22.com/image/534173/%E5%9C%A8%20nginx%20%E4%B8%AD%E7%9A%84%E5%AD%90%E8%B7%AF%E5%BE%84%E4%B8%AD%E9%85%8D%E7%BD%AE%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F.png)
我在 Fedora 服务器上设置了一个 nginx + 乘客 + 单轨应用程序。我的应用程序的 nginx.conf 如下所示:
server {
listen 80;
server_name myapp.mycompany.com;
root /opt/apps/myapp_large_name/public;
passenger_enabled on;
client_max_body_size 4M;
}
因此,当我访问 myapp.mycompany.com.br 时,它会访问 /opt/apps/myapp_large_name/public 下的 rails 应用程序。我希望能够配置一个子路径来访问另一个应用程序(在本例中为 monit)。我想要这样的东西:
myapp.mycompany.com.br/monit 访问 monit 应用程序。
是否可以?
答案1
找到了一种方法来做到这一点:
server {
listen 80;
server_name name myapp.mycompany.com;
root /opt/apps/myapp_large_name/public;
passenger_enabled on;
client_max_body_size 4M;
location /monit/ {
rewrite ^/monit/(.*)$ /$1 break;
proxy_pass http://localhost:2812;
}
}