Nginx Magento vhost Configuration

From Brian Nelson Ramblings
Revision as of 19:35, 10 February 2014 by Brian (Talk | contribs) (Created page with "==Nginx - Magento vhost Configuration== The web is all about speed, the faster your site the better your search results. One way to increase your sites speed is to use Nginx...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Nginx - Magento vhost Configuration

The web is all about speed, the faster your site the better your search results. One way to increase your sites speed is to use Nginx, Nginx is light weight and powerful.

Working for a company that specializes in Magneto web hosting, that primarily uses Apache, I thought I would setup a site using Nginx. To check the if that makes a large difference.

After installing Nginx and getting the server aspects setup, you will want to configure your vhost file with the default .htaccess rules that come with Mangento.

Here is the configurations from Nginx - http://wiki.nginx.org/Magento

They have two separate configurations for Magento versions.

This config works for version 1.7 - and above

server {
 root	   /home/magento/web/;
 index	   index.php;
 server_name	magento.example.com;
 location / {
   index index.html index.php;
   try_files $uri $uri/ @handler;
   expires 30d;
 }
 location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
 location /var/export/ { internal; }
 location /. { return 404; }
 location @handler { rewrite / /index.php; }
 location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
 location ~* .php$ {
   if (!-e $request_filename) { rewrite / /index.php last; }
   expires off;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   fastcgi_param MAGE_RUN_CODE default;
   fastcgi_param MAGE_RUN_TYPE store;
   include fastcgi_params;
 }
}

This config currently seems to work for the <1.4 versions

server {
 server_name example.com;
 root /var/www/vhost/example.com/htdocs;
 access_log /var/log/nginx/example.com.access.log main;
 index index.php;

 location / {
   try_files $uri $uri/ /index.php?$args; 
 }

 # set a nice expire for assets
 location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
   expires    max;
   add_header Cache-Control public;
 }

 # the downloader has its own index.php that needs to be used
 location ~* ^(/downloader|/js|/404|/report)(.*) {
   include fastcgi_params;
   fastcgi_index index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$1/index.php$1;
   fastcgi_read_timeout 600;
   fastcgi_pass  127.0.0.1:9000;
 }

 location ~* \.php {
   include fastcgi_params;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   fastcgi_read_timeout 600;
   fastcgi_pass  127.0.0.1:9000;
 }

}