Nginx + Passenger在不同的子URI中提供Rails应用 [英] Nginx + Passenger to serve rails apps in different sub URIs

查看:69
本文介绍了Nginx + Passenger在不同的子URI中提供Rails应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Debian服务器(ip 192.168.1.193)中运行Rails应用,乘客是独立的

I'm running a rails app in a Debian server (ip 192.168.1.193) with passenger as a standalone

$ cd /home/hector/webapps/first
$ passenger start -a 127.0.0.1 -p 3000

我想为该应用提供服务,将带有反向代理的Nginx放在另一个子文件夹中,如下所示:

And I want to serve this app throw Nginx with reverse proxy in a different sub folder as:

http://192.168.1.193/first

我的nginx.conf服务器:

My nginx.conf server:

...
server {
    listen 80;
    server_name 127.0.0.1;
    root /home/hector/webapps/first/public;
    passenger_base_uri /first/;
    location /first/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
    }
}
...

然后我运行Nginx服务器

Then I run the Nginx server

$ /opt/nginx/sbin/nginx

使用此配置运行一个Rails应用程序,一切似乎正常.

With one rails app running with this configuration everything seems to work ok.

但是当我尝试添加第二个应用程序

But when I try to add my second app

$ cd /home/hector/webapps/second
$ passenger start -a 127.0.0.1 -p 3001

使用此nginx.conf文件:

with this nginx.conf file:

...
server {
    listen 80;
    server_name 127.0.0.1;
    root /home/hector/webapps/first/public;
    passenger_base_uri /first/;
    location /first/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
    }
}

server {
    listen 80;
    server_name 127.0.0.1;
    root /home/hector/webapps/second/public;
    passenger_base_uri /second/;
    location /second/ {
        proxy_pass http://127.0.0.1:3001;
        proxy_set_header Host $host;
    }
}
…

然后我重新加载Nginx服务器配置

and I reload the Nginx server configuration

$ /opt/nginx/sbin/nginx -s reload
nginx: [warn] conflicting server name "127.0.0.1" on 0.0.0.0:80, ignored

我收到警告,但无法从中访问第二个应用程序

I get a warning and I cannot access the second app from

http://192.168.1.193/second/ 

服务器为第二个应用返回404,而第一个应用仍在运行.

The server returns 404 for the second app and the first app is still running.

推荐答案

我认为您只需要将两个位置都放在同一台服务器中即可.

I think you just have to put both locations into the same server:

server {
  listen 80;
  server_name 127.0.0.1;

  location /first/ {
    root /home/hector/webapps/first/public;
    passenger_base_uri /first/;

    proxy_pass http://127.0.0.1:3000/;
    proxy_set_header Host $host;
  }
  location /second/ {
    root /home/hector/webapps/second/public;
    passenger_base_uri /second/;

    proxy_pass http://127.0.0.1:3001/;
    proxy_set_header Host $host;
  } 

}

这篇关于Nginx + Passenger在不同的子URI中提供Rails应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆