Last active
October 4, 2016 05:46
-
-
Save artttj/1d698361aef91d5e135621d61ea1b9c9 to your computer and use it in GitHub Desktop.
Magento NGINX Server Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
root /home/me/domains/example; | |
index index.html index.php; | |
server_name example.dev; | |
## | |
# redirect to www | |
## | |
#if ($host !~* ^www\.) { | |
# rewrite ^(.*)$ http://www.$host$1 permanent; | |
#} | |
## | |
# dont log robots.txt requests | |
## | |
location /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
## These locations would be hidden by .htaccess normally | |
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 /var/export/ { deny all; } | |
# deny htaccess files | |
location ~ /\. { | |
deny all; | |
access_log off; | |
log_not_found off; | |
} | |
## | |
# Rewrite for versioned CSS+JS via filemtime | |
## | |
location ~* ^.+\.(css|js)$ { | |
rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last; | |
expires 31536000s; | |
access_log off; | |
log_not_found off; | |
add_header Pragma public; | |
add_header Cache-Control "max-age=31536000, public"; | |
} | |
## | |
# Aggressive caching for static files | |
# If you alter static files often, please use | |
# add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; | |
## | |
location ~* \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|t?gz|tif|tiff|ttf|wav|webm|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$ { | |
expires 31536000s; | |
access_log off; | |
log_not_found off; | |
add_header Pragma public; | |
add_header Cache-Control "max-age=31536000, public"; | |
} | |
# error pages | |
error_page 404 /404.html; | |
location = /404.html { | |
root /usr/share/nginx/html; | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
location / { | |
try_files /maintenance.html $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler | |
expires 30d; ## Assume all files are cachable | |
} | |
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; | |
} | |
## | |
# pass the PHP scripts to FastCGI server listening at unix:/tmp/php5-fpm.sock | |
## | |
location ~ \.php$ { | |
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss | |
fastcgi_split_path_info ^(.+\.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; | |
# fastcgi_param MAGE_RUN_CODE $store; | |
# fastcgi_param MAGE_RUN_TYPE "store"; | |
# With php5-fpm: | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment