使用nginx在不同的sub-URI下为同一个域运行多个Rails应用程序

我能够成功configurationnginx和乘客注册。 我现在有以下configuration

server {listen 80 server_name **sub1.example.com** root /home/user/app1/public } server {listen 80 server_name **sub2.example.com** root /home/user/app2/public } 

现在,我想将其更改为以下configuration

 server {listen 80 server_name **dev.example.com/example1** root /home/user/app1/public } server {listen 80 server_name **dev.example.com/example2** root /home/user/app2/public } 

我尝试使用位置指令,但没有成功。 我甚至不确定这是否可能。 任何帮助将不胜感激。 谢谢。

以下是我的nginx.conf设置

 server { listen 80; server_name dev.example.com; location = /app1/ { root /home/rails/app1/public/; passenger_enabled on; rails_env development; } location /app2/ { root /home/rails/app2/public/; passenger_enabled on; rails_env development; } } 

以前的答案:

  server_name dev.example.com/example1 

是错的。 我正在理解你想要dev.example.com去dev.example.com/example1。 对于这种情况,你需要做如下的URL重写

 location = / { rewrite ^ http://dev.example.com/example1 ; } 

回答后评论:

从你的评论我明白你想在同一个URI /域内提供多个rails应用程序。

 server { listen 80; server_name dev.example.com; root /home/user/app1/public; passenger_enabled on; passenger_base_uri /app2; passenger_base_uri /app3; ....truncated... rails_spawn_method smart; rails_env production; } 

这可以通过使用Passenger Phusion的passenger_base_uri指令来实现。 让我们假设我的域名是www.example.com

现在我想为以下URI运行多个rails应用程序

www.example.com – 加载Rails App1

www.example.com/app2 – 加载Rails App2

这是我在nginx.conf中的服务器块如何看起来像:

 server { listen 80; server_name www.example.com; root /var/www/app1/public; passenger_enabled on; passenger_base_uri /app2; } 

看看根指向app1的公用文件夹的方式。 看看passenger_base_uri指令。

现在我们需要执行最后一步 – 将app2的公共文​​件夹符号链接到/var/www/app1/public/app2 ,这是通过运行以下命令完成的:

ln -s /var/www/app2/public /var/www/app1/public/app2

一旦你创build了这个链接,重新启动nginx,你就可以在同一个域上为不同的Rails应用程序提供服务。

参考:将Passenger Phusion部署到一个子URI