I have a single Nginx instance with passenger and would like to serve different Rails apps at different routes. Specifically: /api
should serve one app and /
should serve a different. My Rails apps are located at /srv/api/
and /srv/ui
on the filesystem.
My Nginx config is currently like this:
user foo;
worker_processes 1;
events { worker_connections 1024; }
http {
passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-4.0.49;
passenger_ruby /home/monolith/.rvm/gems/ruby-2.1.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /srv/ui/public/;
passenger_enabled on;
}
location /api {
root /srv/api/public/;
passenger_enabled on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
With this config, the API app is being served correctly, but the UI app is not. It returns a 500 error, and there are no error logs in either Nginx or under logs in Rails.
Attempted solutions / debugging echo 'test' > /srv/ui/public/index.html
. This results in a successful render of 'test'
when visiting <hostname>.com/
Changing location /
to serve a static index.html using the alias
directive instead. This works also.
I saw this solution of symlinking a file inside the /
location https://www.chiliproject.org/boards/1/topics/545 , but this would be relevant if the API app was not being served.
I suspect this has something to do with interference among passenger instances, but I don't know what the solution is.
We've achieved this before (albeit with Apache - maybe we can work towards a port for Nginx):
#app/apache2/apache2.conf
<VirtualHost *:80>
ServerName *********.co.uk
DocumentRoot /apps/[main_app]/current/public
<Directory /apps/[main_app]/current/public>
Allow from all
Options -MultiViews
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
#Secondry App
Alias /[app_name] /apps/[app_name]/current/public
<Location /[app_name]>
PassengerAppRoot /apps/[app_name]/current
RackEnv production
RackBaseURI /[app_name]
</Location>
</VirtualHost>
In terms of Nginx, you may be able to get away with the following:
#etc/nginx/nginx.conf
http {
server {
listen 80;
server_name yourdomain.com;
#serve your "main" site here
root /srv/ui/public/;
passenger_enabled on;
#serve your "API" app from the location / Alias
location /api {
root /srv/api/public/;
passenger_enabled on;
}
}
}
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.