Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created October 22, 2012 14:13
Show Gist options
  • Select an option

  • Save EdwardIII/3931690 to your computer and use it in GitHub Desktop.

Select an option

Save EdwardIII/3931690 to your computer and use it in GitHub Desktop.
server {
listen 80;
server_name example.com;
#charset koi8-r;
#access_log /var/log/nginx/www.example.com.access.log main;
root /home/example/public_html/;
location /products {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
expires 30d; ## Assume all files are cachable
}
#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 /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
location ^~ /products/app/ { deny all; }
location ^~ /products/includes/ { deny all; }
location ^~ /products/lib/ { deny all; }
location ^~ /products/media/downloadable/ { deny all; }
location ^~ /products/pkginfo/ { deny all; }
location ^~ /products/report/config.xml { deny all; }
location ^~ /products/var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location ~ \.php$ {
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#try_files $uri =404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler { ## Magento uses a common front handler
rewrite /products /products/index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment