简体   繁体   English

在 nginx 上运行多个 Ruby on Rails 应用程序

[英]Run multiple Ruby on Rails applications on nginx

I'm trying to run multiple Ruby on Rails apps on nginx server.我正在尝试在 nginx 服务器上运行多个 Ruby on Rails 应用程序。 I set up the conf file as below:我设置的conf文件如下:

server {
        listen 80;
        #server_name 10.0.1.216;

        # Tell Nginx and Passenger where your app's 'public' directory is

        location / {
                root /var/www/app-one/public;
        }

        location /dev {
                root /var/www/app-two/public;
        }

        # Turn on Passenger
        passenger_enabled on;
        passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.4.1/wrappers/ruby;

    }

The first app works fine when I access http://myurl .当我访问http://myurl时,第一个应用程序运行良好。 However, when I access http://myur/dev , nginx throws me below exception.但是,当我访问http://myur/dev 时,nginx 将我抛出以下异常。 Can anyone help me figure it out?谁能帮我弄清楚吗?

在此处输入图片说明

You should configure nginx according to this tutorial: https://www.phusionpassenger.com/library/deploy/nginx/deploy/ruby/#deploying-an-app-to-a-sub-uri-or-subdirectory您应该根据本教程配置 nginx: https : //www.phusionpassenger.com/library/deploy/nginx/deploy/ruby/#deploying-an-app-to-a-sub-uri-or-subdirectory

server {
    listen 80;
    root /var/www/app-one/public;
    passenger_enabled on;

    # This block has been added.
    location ~ ^/dev(/.*|$) {
        alias /var/www/app-two/public$1;  # <-- be sure to point to 'public'!
        passenger_base_uri /dev;
        passenger_app_root /var/www/app-two;
        passenger_document_root /var/www/app-two/public;
        passenger_enabled on;

    }
}

Try reordering your locations尝试重新排序您的位置

server {
    # ...

    location /dev {
            root /var/www/app-two/public;
    }

    location / {
            root /var/www/app-one/public;
    }

    # ...
}

As per the docs http://nginx.org/en/docs/http/ngx_http_core_module.html#location根据文档http://nginx.org/en/docs/http/ngx_http_core_module.html#location

The search of regular expressions terminates on the first match, and the corresponding configuration is used正则表达式的搜索在第一次匹配时终止,并使用相应的配置

The / will match all paths since all paths start this way. /将匹配所有路径,因为所有路径都以这种方式开始。

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

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