Nginx short configuration for Magento site

Posted . Visible to the public.

To be used locally for development:


server {
    listen       80;
    server_name  magento.dev;
    root   /usr/share/nginx/html/magento.dev;
    access_log  /var/log/nginx/$host.access.log  main;
    
    location / {
        index  index.html index.htm index.php;
	try_files $uri $uri/ @handler;
    }

    error_page   500 502 503 504  /50x.html;

    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

    location  /. {
        return 404;
    }

    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    ## Rewrite URLs to Magento front handler
    location @handler {
	rewrite / /index.php;
    }
    
    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }

    ## Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
	if ( !-e $request_filename) { rewrite / /index.php last; }
	expires		off;
        fastcgi_pass   	127.0.0.1:9000;
        fastcgi_index  	index.php;
        fastcgi_param  	SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	fastcgi_param 	MAGE_RUN_CODE default;
	fastcgi_param	MAGE_RUN_TYPE store;
        include        	fastcgi_params;
    }

}

Last edit
Dan