Skip to content

Instantly share code, notes, and snippets.

@nzajt
Created July 2, 2014 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzajt/bc2aef5074172ca0f5c2 to your computer and use it in GitHub Desktop.
Save nzajt/bc2aef5074172ca0f5c2 to your computer and use it in GitHub Desktop.
Magento Nginx host file
server {
listen 80 default;
listen 443 ssl;
ssl_certificate PATHTOSSL.crt;
ssl_certificate_key PATHTOSSL.key;
server_name www.SITEURL.com *.SITEURL.com; ## Domain is here twice so server_name_in_redirect will favour the www
root PATH TO MAGENTO ROOT;
autoindex off;
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 = /RELEASE_NOTES.txt { deny all; }
location = /LICENSE_AFL.txt { deny all; }
location = /LICENSE.html { deny all; }
location = /LICENSE.txt { deny all; }
location = /php.ini.sample { deny all; }
location = /index.php.sample { deny all; }
location /. { return 404; }
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico|txt|xml|bmp|pdf|doc|docx|ppt|pptx|zip)$ {
access_log off;
expires 30d;
}
location ~* ^(/downloader|/js|/404|/report)(.*) {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$1/index.php$1;
fastcgi_read_timeout 600;
fastcgi_pass fpm_backend;
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ \.php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*\.php)/ $1 last;
}
location ~ \.php$ { ## Execute PHP scripts
expires off; ## Do not cache dynamic content
fastcgi_pass fpm_backend;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
location / {
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
expires 30d; ## Assume all files are cachable
if ($request_uri ~* "\.(png|gif|jpg|jpeg|css|js|swf|ico|txt|xml|bmp|pdf|doc|docx|ppt|pptx|zip)$") {
expires max;
}
# set fastcgi settings, not allowed in the "if" block
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$; #this line
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
# rewrite - if file not found, pass it to the backend
if (!-f $request_filename) {
fastcgi_pass fpm_backend;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment