Skip to content

Instantly share code, notes, and snippets.

@hn-support
Last active January 28, 2020 15:11
Show Gist options
  • Save hn-support/232aa50cd89476aacb54efb6aa56efd8 to your computer and use it in GitHub Desktop.
Save hn-support/232aa50cd89476aacb54efb6aa56efd8 to your computer and use it in GitHub Desktop.

Revisions

  1. hn-support revised this gist Jan 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion server.shopware
    Original file line number Diff line number Diff line change
    @@ -103,7 +103,7 @@ location /recovery/update/ {


    ## All static files will be served directly.
    location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|svg|html|pdf)$ {
    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;
  2. hn-support revised this gist Jan 10, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion server.shopware
    Original file line number Diff line number Diff line change
    @@ -103,7 +103,7 @@ location /recovery/update/ {


    ## All static files will be served directly.
    location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|svg|html)$ {
    location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|svg|html|pdf)$ {
    ## Defining rewrite rules
    rewrite files/documents/.* /engine last;
    rewrite backend/media/(.*) /media/$1 last;
  3. hn-support revised this gist Feb 22, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions server.shopware
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ 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;
    @@ -61,6 +61,7 @@ location ^~ /files/552211cce724117c3178e3d22bec532ec/ {
    internal;
    }

    ###Install rewrite
    # Shopware install / update
    location /recovery/install {
    index index.php;
    @@ -74,7 +75,7 @@ location /recovery/update/ {
    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)$" {
    @@ -154,6 +155,7 @@ location = /robots.txt {
    try_files $uri @shopware;
    }

    ###General rewrites
    location @shopware {
    rewrite / /shopware.php;
    }
  4. hn-support created this gist Feb 22, 2019.
    167 changes: 167 additions & 0 deletions server.shopware
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,167 @@
    ## 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;
    }

    ## 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;
    }

    # 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;
    }
    }

    # 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)$ {
    ## 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;
    }

    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;
    }