简体   繁体   中英

Run multiple Ruby on Rails applications on nginx

I'm trying to run multiple Ruby on Rails apps on nginx server. I set up the conf file as below:

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 . However, when I access http://myur/dev , nginx throws me below exception. 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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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