简体   繁体   English

使用Passenger for Nginx部署多个Ruby应用程序(Rails和Sinatra)?

[英]Multiple Ruby apps (Rails and Sinatra) deployed using Passenger for Nginx?

I have two Ruby applications, one is under Rails and the another is under Sinatra. 我有两个Ruby应用程序,一个在Rails下,另一个在Sinatra下。

How can I deploy both these apps in Nginx and Passenger with one in the root ("localhost:3000") and the other in subroot ("localhost:3000/test")? 如何在Nginx和Passenger中部署这些应用程序,其中一个在根目录(“localhost:3000”)中,另一个在subroot中(“localhost:3000 / test”)?

The Rails application is running with this configuration. Rails应用程序正在使用此配置运行。 Everything seems to work OK: 一切似乎都运作正常:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /var/www/demo/public;
        passenger_enabled on;
        rails_env production;
    }

    location /test/ {
        root   /var/www/test/public;
        passenger_base_uri /test/;
        proxy_pass http://10.0.3.12:80/test/;
        passenger_enabled on;
    }

I am not able to access the second application. 我无法访问第二个应用程序。

The server returns 404 for the second app and the first app is still running. 服务器为第二个应用程序返回404,第一个应用程序仍在运行。

I believe you need to define local servers, that only listen on local port and define your passenger apps there. 我相信您需要定义本地服务器,只能在本地端口上侦听并在那里定义您的乘客应用程序。 Your actual server listening on port should only act as proxy. 您在端口上侦听的实际服务器应仅充当代理。

server {
  listen              localhost:8181;
  server_name         test_app;
  root                /var/www/test/public;
  passenger_enabled  on;
}

server {
  listen              localhost:8182;
  server_name         demo_app;
  root                /var/www/demo/public;
  passenger_enabled   on;
  rails_env production;
}

server {
  listen       80;
  server_name  localhost;

  location / {
    proxy_pass http://localhost:8182/;
  }

  location /test/ {
    proxy_pass http://localhost:8181/;
  }
}

I didn't have chance to test this config, so it might have some minor flaws, but it should be correct in high-level terms. 我没有机会测试这个配置,所以它可能有一些小的缺陷,但它在高级术语中应该是正确的。

In nginx.conf: 在nginx.conf中:

server {
   listen       80;
   server_name  localhost;
   location / {
       root   /var/www/new/public;
       passenger_enabled on;
       rails_env production;
   }
location /test {
    root   /var/www/demo;
    passenger_base_uri /test;
    passenger_enabled on;   
}

Add a soft link: 添加软链接:

ln -s /var/www/loggerapp/public /var/www/new/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM