Showing posts with label passenger. Show all posts
Showing posts with label passenger. Show all posts

Friday, March 26, 2010

nginx and thin installation and configuration

by sandipransing 0 comments

Install nginx server using following command

apt-get install nginx Edit nginx configuration and add server block inside html block. 
server {
    listen       80;
    server_name  boost;

    root /home/sandip/rails_app/public;

    location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
        }
        if (!-f $request_filename) {
            proxy_pass http://thin;
            break;
        }
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Install thin server as gem
sudo gem install thin

Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed eventmachine-0.12.10
Successfully installed thin-1.2.7
2 gems installed

Install thin service
sudo thin install
Installing thin service at /etc/init.d/thin ...
mkdir -p /etc/init.d
writing /etc/init.d/thin
chmod +x /etc/init.d/thin
mkdir -p /etc/thin

Configure thin to start at system boot
sudo /usr/sbin/update-rc.d -f thin defaults

Then put your config files in /etc/thin
sudo /usr/sbin/update-rc.d -f thin defaults
update-rc.d: warning: thin stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (S 0 1 6)
 Adding system startup for /etc/init.d/thin ...
   /etc/rc0.d/K20thin -> ../init.d/thin
   /etc/rc1.d/K20thin -> ../init.d/thin
   /etc/rc6.d/K20thin -> ../init.d/thin
   /etc/rc2.d/S20thin -> ../init.d/thin
   /etc/rc3.d/S20thin -> ../init.d/thin
   /etc/rc4.d/S20thin -> ../init.d/thin
   /etc/rc5.d/S20thin -> ../init.d/thin

Create thin configuration
sudo thin config -C /etc/thin/<config-name>.yml -c <rails-app-root-path> --servers <number-of-threads> -e <environment>
</environment></number-of-threads></rails-app-root-path></config-name>

In my case,
sudo thin config -C /etc/thin/rails_app.yml -c /home/sandip/rails_app --servers 3 -e production
&gt;&gt; Wrote configuration to /etc/thin/rails_app.yml

thin configuration file will look like

Start/stop/restart Nginx &amp; thin server using command

sudo service nginx start|stop|restart
sudo service thin start|stop|restart
Read More…

Monday, February 15, 2010

nginx passenger configuration for rails application

by sandipransing 0 comments

#user  nobody;
user www-data;
worker_processes  2;

#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 /var/lib/gems/1.8/gems/passenger-2.2.8;
    passenger_ruby /usr/bin/ruby1.8;
    passenger_max_pool_size 3;

    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;
     root /home/josh/current/public;   # <--- be sure to point to 'public'!
     passenger_enabled on;
     passenger_use_global_queue on;
   }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
     #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;
        }
   }
}
Read More…

Wednesday, September 9, 2009

4 steps to install nginx with passenger

by sandipransing 2 comments
Install passenger program that will run your rails application
1. sudo gem install passenger
Install nginx server with passenger enabled
2. passenger-install-nginx-module

it will open apt, click "Enter" to contine
then select option 1 for default install
then it will ask
Where do you want to install Nginx to?

Please specify a prefix directory [/opt/nginx]:
press enter

then copy following block

server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public;   # <--- be sure to point to 'public'!
passenger_enabled on;
}


Make nginx Configuration
3. vi /opt/nginx/conf/nginx.conf
Make passenger_root and passenger_ruby path to configuration


http {
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.4;
passenger_ruby /usr/local/bin/ruby;


then add server configuration block inside http block
http{
...
server {
listen 80;
server_name www.yourhost.com; //Make sure this dns entry inside /etc/hosts
root /carsonline/public;   # <--- be sure to point to 'public'! //here carsonline is RAILS_ROOT
passenger_enabled on;
}


Thats, all

4. Launch Server

/opt/nginx/sbin/nginx
Read More…

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter