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.

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")?

The Rails application is running with this configuration. 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.


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:

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
链接地址: http://www.djcxy.com/p/32488.html

上一篇: nginx乘客轨道没有收到数据

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