Nginx Rule for Rails Application

Use following code for setting up Nginx for rails.

http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;</code>

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  /var/log/nginx/access.log  main;

# Timeouts
client_body_timeout   5;
client_header_timeout 5;
keepalive_timeout     55;
send_timeout          5;

upstream mongrel_cluster {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
}
server {
listen       80;
server_name  localhost.localdomain;
#charset koi8-r;
#access_log  logs/host.access.log  main;

#for images routing
location ~* ^/(images|stylesheets|javascripts).+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /var/www/html/Projects/Project_Name/public;
}
# concurs with nginx's one

location  / {
proxy_pass	http://mongrel_cluster;
#Fix for host name and redirection to domain

}

}

<code>

NginX Rule for WordPress Mu with Pretty Url

I am using wordpressmu 2.6.5, quite old version. Three month back i moved our site Apache to Nginx. Now these day nobody use wordpress mu. Still article can be used for wordpress multisite.

NginX Rule for WordPress Mu with Pretty Url

Nginx i am using for Rails and WordPressmu application.

I am able to run wordpressmu and Clean Urls(Pretty Url) successfully. I am using Fedora 9 as OS.
“/usr/share/nginx/html/wordpress” – This is my path where i installed WordPressmu

Here is my Nginx code:


server {
listen 80;
server_name localhost.localdomain;
# access_log logs/site.access.log;

location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /usr/share/nginx/html/wordpress;
rewrite ^/.*(/wp-admin/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-includes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/themes/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^/.*(/wp-content/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last;
rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /wp-content/blogs.php?file=$1 last;
expires 10d;
break;
}

location / {
root /usr/share/nginx/html;
index index.php;

rewrite ^.*/.*/files/(.*) /wordpress/wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) /wordpress$1 last;
rewrite ^.+?(/.*\.php)$ /wordpress$1 last;
rewrite ^(.+)$ /wordpress/index.php?q=$1 last;
break;
}

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
include fastcgi_params;

}

location = /50x.html {
root /var/www/nginx-default;
}

}

This code is working fine for me.

Easy Steps for setting up nginx with php on Linux

I am using Fedora 10 so for that linux version i used these commands for setting up my server.

Installing Nginx:
yum install nginx

Then we create the system startup links for nginx:
/sbin/chkconfig –level 35 nginx on

We can make PHP5 work in nginx through FastCGI.For that install all this packages:
yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy

Then open /etc/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:
vi /etc/php.ini
paste this line :- cgi.fix_pathinfo = 1

To start a PHP FastCGI daemon listening on port 9000 on localhost and running as the user and group nginx, we run the following command:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

To restart PHP FastCGI daemon, Use this command:
ps -ef|grep php-cgi
kill PROCESS_ID

you don’t want to type in that command manually whenever you boot the system, so to have the system execute the command automatically at boot time, open /etc/rc.local…
vi /etc/rc.local
and add the command at the end of the file:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx  -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid

THEN STOP THE APACHE WEB SERVER:
/sbin/init.d/httpd stop
To stop apache on every startup:
/sbin/chkconfig –level 35 httpd off

First take backup of your nginx configuration file:
cp /etc/nginx/nginx.conf nginx.conf_cp
use nginx.conf file from life180 “config/nginx” folder