Shopware Nginx configuration
## Author: Benjamin Cremer | |
## Shopware nginx rules. | |
## Heavily Inspired by https://github.com/perusio/drupal-with-nginx/ | |
## Designed to be included in any server {} block. | |
## Please note that you need a PHP-FPM upstream configured in the http context, and its name set in the $fpm_upstream variable. | |
## https://github.com/bcremer/shopware-with-nginx | |
# don't log favicon hits | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
### Security | |
## Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). | |
location ~ /\. { | |
deny all; | |
access_log off; | |
log_not_found off; | |
} | |
## Deny all attems to access possible configuration files | |
location ~ \.(tpl|yml|ini|log)$ { | |
deny all; | |
} | |
## Deny access to media upload folder | |
location ^~ /media/temp/ { | |
deny all; | |
} | |
# Shopware caches and logs | |
# already defined on hypernode | |
#location ^~ /var/ { | |
# deny all; | |
#} | |
# Deny access to root files | |
location ~ (autoload\.php|composer\.(json|lock|phar)|CONTRIBUTING\.md|eula.*\.txt|license\.txt|README\.md|UPGRADE-(.*)\.md|.*\.dist)$ { | |
return 404; | |
} | |
# Restrict access to shop configs files | |
location ~ /(web\/cache\/(config_\d+\.json|all.less))$ { | |
return 404; | |
} | |
# Restrict access to theme configurations | |
location ~ /themes/(.*)(.*\.lock|package\.json|Gruntfile\.js|all\.less)$ { | |
return 404; | |
} | |
location ^~ /files/documents/ { | |
deny all; | |
} | |
# Block direct access to ESDs, but allow the follwing download options: | |
# * 'PHP' (slow) | |
# * 'X-Accel' (optimized) | |
# Also see http://wiki.shopware.com/ESD_detail_1116.html#Ab_Shopware_4.2.2 | |
location ^~ /files/552211cce724117c3178e3d22bec532ec/ { | |
internal; | |
} | |
###Install rewrite | |
# Shopware install / update | |
location /recovery/install { | |
index index.php; | |
try_files $uri /recovery/install/index.php$is_args$args; | |
} | |
location /recovery/update/ { | |
location /recovery/update/assets { | |
} | |
if (!-e $request_filename){ | |
rewrite . /recovery/update/index.php last; | |
} | |
} | |
###Optimizations | |
# todo fix correct theme | |
#location / { | |
location ~* "^/themes/Frontend/Responsive/frontend/_public/vendors/fonts/open-sans-fontface/(?:.+)\.(?:ttf|eot|svg|woff|woff2)$" { | |
expires max; | |
add_header Cache-Control "public"; | |
access_log off; | |
log_not_found off; | |
} | |
location ~* "^/themes/Frontend/Responsive/frontend/_public/src/fonts/(?:.+)\.(?:ttf|eot|svg|woff|woff2)$" { | |
expires max; | |
add_header Cache-Control "public"; | |
access_log off; | |
log_not_found off; | |
} | |
location ~* "^/web/cache/(?:[0-9]{10})_(?:.+)\.(?:js|css)$" { | |
# all.css isn't being used anymore. css files gets build | |
# rewrite ^/web/cache\/[^_]+_[^\.]+\.(css|js)$ /web/cache/all.$1 break; | |
expires max; | |
add_header Cache-Control "public"; | |
access_log off; | |
log_not_found off; | |
} | |
## All static files will be served directly. | |
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|svg|html|pdf|eot|woff|ttf)$ { | |
## Defining rewrite rules | |
rewrite files/documents/.* /engine last; | |
rewrite backend/media/(.*) /media/$1 last; | |
expires 1w; | |
add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | |
access_log off; | |
# The directive enables or disables messages in error_log about files not found on disk. | |
log_not_found off; | |
tcp_nodelay off; | |
## Set the OS file cache. | |
open_file_cache max=3000 inactive=120s; | |
open_file_cache_valid 45s; | |
open_file_cache_min_uses 2; | |
open_file_cache_errors off; | |
## Fallback to shopware | |
## comment in if needed | |
# try_files $uri empty.txt; | |
try_files $uri /shopware.php?controller=Media&action=fallback; | |
# try_files $uri $uri/ /shopware.php$is_args$args; | |
} | |
# doesn't work here, because of location | |
# index shopware.php index.php; | |
# try_files $uri $uri/ /shopware.php$is_args$args; | |
#} | |
## XML Sitemap support. | |
location = /sitemap.xml { | |
log_not_found off; | |
access_log off; | |
try_files $uri @shopware; | |
} | |
## XML SitemapMobile support. | |
location = /sitemapMobile.xml { | |
log_not_found off; | |
access_log off; | |
try_files $uri @shopware; | |
} | |
## robots.txt support. | |
location = /robots.txt { | |
log_not_found off; | |
access_log off; | |
try_files $uri @shopware; | |
} | |
###General rewrites | |
location @shopware { | |
rewrite / /shopware.php; | |
} | |
# use shopware.php as index.php | |
location ~ ^/ { | |
# rewrite / /shopware.php; | |
index shopware.php index.php; | |
try_files $uri $uri/ /shopware.php$is_args$args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment