Pages

Saturday 13 April 2013

Nginx: Next generation server--Super light, Super fast

Nginx Conf file


Add the server information in the nginx file


     server {
listen 80 default_server;
server_name localhost
        location / {
            root   /home/deployer/www;
 #          index  index.html index.htm;
        }
        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
   }



    listen 80;
    server_name domain.com;
    charset utf-8;
    root /www/domain.com/public_html;
    passenger_enabled on;
    passenger_base_uri /blog;
    rails_spawn_method smart;
    rails_env production;




Now, you have server listening on port :80 and it's root location is set to /home/deployer/www.
For rails project, your application /public directory should be present there :Create a symlink in www, so that the app is viewable via the web.

 ln -s /home/deployer/www/media_analysis/public /home/deployer/www/media


Nginx start/stop/restart commands:

  • sudo /etc/init.d/nginx stop 
  • sudo /etc/init.d/nginx start 
  • sudo /etc/init.d/nginx restart

Errors:
   404 Not Found Error:
Make sure,  you have "passenger_enabled  on", if multiple server blocks:
                         If you already have passenger_root and passenger_ruby in your nginx.conf, but having this error, you must have some location blocks. Then you must specify passenger_enabled on; inside each location block.

Deploying to a sub URI


                      You already have your server(vhost) configured and you want your Ruby on Rails application to be accessible from the URL http://www.myDomain.nl/rails.
To do this, make a symlink in the virtual host’s document root, and have it point to your Ruby on Rails application’s public folder. For example:

ln -s /webapps/newApp/public /websites/myDomain/rails

Next, set 'passenger_enabled on' and add a 'passenger_base_uri' option to the server block:

http {
    ...

    server {
        listen 80;
        server_name www.myDomain.nl;
        root /websites/myDomain;
        passenger_enabled on;        # <--- These lines have
        passenger_base_uri /rails;   # <--- been added.
    }

    ...
}



References:

  1. http://techoctave.com/c7/posts/16-how-to-host-a-rails-app-with-phusion-passenger-for-nginx
  2. http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_ror_app
  3. http://alexpearce.me/2012/06/setting-up-a-vps/




No comments:

Post a Comment