ChiliProject is not maintained anymore. Please be advised that there will be no more updates.
We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.
unable to run multiple rails apps on passenger+nginx
Added by Nagaraj Ganachari at 2011-07-04 12:30 pm
Hi all,
I want to run multiple rails applications on passenger+nginx.
I am trying to run two seperate applications, chiliproject and
gitorious(mainline)
I have tried the below steps to setup sub_uri.
http://www.modrails.com/documentation/Users%20guide%20Nginx.html
I am not able to run the applications as
how to setup sub_uri to run more than one rails applications.
steps to reproduce
1) my nginx.conf is
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { passenger_root /opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/passenger-3.0.7; passenger_ruby /opt/ruby-enterprise-1.8.7-2011.03/bin/ruby; include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local]"$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /home/chiliproject/chiliproject-2.0.0RC3/public; index login; passenger_enabled on; passenger_base_uri /mainline/public; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW: +SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
2) ln -s /home/chiliproject/mainline/public /home/chiliproject/chiliproject-2.0.0RC3/mainline
please help.
Thanks...
Nagaraj P G
Replies (1)
RE: unable to run multiple rails apps on passenger+nginx - Added by Holger Just at 2011-07-04 01:16 pm
Nagaraj,
First, I fixed your formatting so I can understand what you are trying to do...
Then judging from your config, you mix up a whole lot of concepts and ideas regarding application deployment, esp. on Passenger.
The basic idea is that you have Rails applications somewhere on your disk. Now you need to configure your Nginx that it finds those Rails applications and binds them to a URL path. This is important to understand. You basically define a mapping from a URL path to a filesystem path (hence a Rails application living there).
Passenger has two distinct variants on achieving this.
The first variant is for root installs, i.e. when your Rails application should be served from the root path of your web host with a URL like http://example.com/
. This is achieved by setting the root
of a server to the public directory of a rails app which you do in your location block.
The seconds variant is to have apps at another path, different from /, like e.g. /mainline
. This requires two configuration steps:
- You need to tell nginx (hence passenger) that a certain URL path should be considered a Rails app. This can be done using the
passenger_base_uri
statement. - You need to help passenger find the application in the filesystem.
When recieving a request for a URL, passenger tries to find the location of the app in the filesystem by first mapping the requested URL to the filesystem as is would normally do (by using the root
and location
directives). As you have told passenger that a certain URL path is a rails app, it tries to find a matching symlink pointing to that app in the filesystem.
So consider the following setup:
server { listen 80; server_name example.com; root /srv/www; passenger_base_uri /mainline; }
With this setup, passenger expects a symlink in the filesystem at /srv/www/mainline
pointing to the public directory of a rails app (like /home/chiliproject/mainline/public
in your case). With that in place, it finds the application and properly starts it.
Now we have a third variant, namely when you want to have a rails app at the root and another one in a subpath, which seems what you want to achieve. Then, you have to setup the application at the root first. as you would normally do. See the guide for that. Then you need to create a symlink inside the public directory of the first app, as this very public directory is defined as the root dir of that server.
Concluding: I guess, it should work if you create your symlink like this instead:
ln -s /home/chiliproject/mainline/public /home/chiliproject/chiliproject-2.0.0RC3/public/mainline
Also, your passenger_base_uri
has to be a URI path, not a filesystem path. So it has to point to /mainline
. Again, it's important to understand the difference between a filesystem path and a URI path and that nginx and passenger define a mapping between those.
Hope that helps,
Holger
(1-1/1)