简体   繁体   English

如何使用Nginx,Passenger,Sinatra创建多个位置

[英]How do I create multiple locations with Nginx, Passenger, Sinatra

I have a server section that looks like: 我有一个服务器部分,看起来像:

server {
    listen       80;
    server_name  arch;
    root   /data/apps/production/fentonGem2/current/public;
    passenger_enabled on;
}

which works fine. 效果很好。 However, I'd like to deploy two or more apps to the same server_name and listen port. 但是,我想将两个或多个应用程序部署到相同的server_namelisten端口。 So presumably I'd use something like the following: 因此,大概我将使用以下内容:

server {
    listen       80;
    server_name  arch;
    location /app1 {
         root   /data/apps/production/fentonGem2/current/public;
         passenger_enabled on;
    }
    location /app2 {
         root   /data/apps/production/fentonGem3/current/public;
         passenger_enabled on
    }
} 

But that doesn't work. 但这是行不通的。 Does anyone know how I can deploy two separate apps, and reach them by: 有谁知道我如何部署两个单独的应用程序,并通过以下方式访问它们:

http://domain.com/app1/

and: 和:

http://domain.com/app2/

The setup uses Nginx, Phusion Passenger, Rack, and Sinatra. 该设置使用Nginx,Phusion Passenger,Rack和Sinatra。


UPDATE: 更新:

Thanks for the responses, but I found them and the approach not helpful, though maybe I'm not understanding it well. 感谢您的答复,但是我发现它们和方法没有帮助,尽管可能我不太了解。 It kind of seems like I have to deploy one application inside another, which seems very unclean. 似乎我必须在另一个应用程序中部署一个应用程序,这似乎很不干净。 What I finally resorted to was having separate server sections, and then updating my /etc/hosts file to have server aliases for the same IP address. 我最终求助于拥有单独的server部分,然后更新我的/etc/hosts文件以具有相同IP地址的服务器别名。 So now I have: 所以现在我有:

http://app1/

and: 和:

http://app2/

and server sections that look like: 和服务器部分如下所示:

server {
    listen       80;
    server_name  app1;
    root /data/apps/production/app1/current/public;        
    passenger_enabled on;        
}               
server {
    listen 80;
    server_name app2;
    root /data/apps/production/app2/current/public;
    passenger_enabled on;
}

and in /etc/hosts: 并在/ etc / hosts中:

192.168.1.30     app1 app2

The following worked: 以下工作:

  1. First made symlinks named app1 and app2 pointing to the "public" directory as follows: 首先创建名为app1app2符号链接,它们指向“公共”目录,如下所示:

     ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app1 ln -s /data/apps/production/fentonGem2/current/public /data/apps/production/fentonGem2/current/app2 
  2. Modify nginx.conf to have rails_base_uri , which should look something like the following: 修改nginx.conf以使其具有rails_base_uri ,其外观应类似于以下内容:

     ... server { listen 80; server_name arch; location ^~ /app1 { root /data/apps/production/fentonGem2/current; rails_env production; passenger_enabled on; passenger_base_uri /app1; } location ^~ /app2 { root /data/apps/production/fentonGem2/current; rails_env production; passenger_enabled on; passenger_base_uri /app2; } } ... 

Hope this helps. 希望这可以帮助。

Not sure, but you might need passenger_base_uri /app1; 不确定,但您可能需要passenger_base_uri /app1;

More about Passenger and Nginx conf: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerBaseURI 有关Passenger和Nginx conf的更多信息: http : //www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerBaseURI

EDIT: 编辑:

"It is allowed to specify this option multiple times. Do this to deploy multiple applications in different sub-URIs under the same virtual host." “允许多次指定此选项。这样做可以在同一虚拟主机下的不同子URI中部署多个应用程序。”

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

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