Created
March 8, 2018 13:16
-
-
Save freedmo/6f021915c68b2e0ec558f4fb21eacb35 to your computer and use it in GitHub Desktop.
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 { | |
server_name shopware.dev www.shopware.dev; | |
root /var/www/shopware; | |
## Access and error logs. | |
access_log /var/log/nginx/shopware.dev.log; | |
error_log /var/log/nginx/shopware.dev.log; | |
set $shopware_env 'production'; | |
## 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 | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
## 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 | |
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; | |
} | |
# 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; | |
} | |
} | |
location / { | |
location ~* "^/themes/Frontend/Responsive/frontend/_public/vendors/fonts/open-sans-fontface/(?:.+)\.(?:ttf|eot|svg|woff)$" { | |
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)$" { | |
expires max; | |
add_header Cache-Control "public"; | |
access_log off; | |
log_not_found off; | |
} | |
location ~* "^/web/cache/(?:[0-9]{10})_(?:.+)\.(?:js|css)$" { | |
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)$ { | |
## 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 /shopware.php?controller=Media&action=fallback; | |
} | |
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; | |
} | |
location @shopware { | |
rewrite / /shopware.php; | |
} | |
location ~ \.php$ { | |
fastcgi_pass php-shopware:9000; | |
fastcgi_split_path_info ^(.+\.php)(/.*)$; | |
include fastcgi_params; | |
fastcgi_read_timeout 180; | |
# When you are using symlinks to link the document root to the | |
# current version of your application, you should pass the real | |
# application path instead of the path to the symlink to PHP | |
# FPM. | |
# Otherwise, PHP's OPcache may not properly detect changes to | |
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 | |
# for more information). | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
fastcgi_param DOCUMENT_ROOT $realpath_root; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment