Want to subscribe to topics you're interested in?
Become a Member

Drupal Centmin Mod Nginx and Drupal 8 configuration

Discussion in 'Blogs & CMS usage' started by Damir, Nov 27, 2018.

  1. Damir

    Damir New Member

    2
    0
    1
    Oct 30, 2018
    Belgrade
    Ratings:
    +0
    Local Time:
    8:25 AM
    1.15
    10.36
    I have no experience using Nginx.
    I installed Drupal 8 ( centminmod 09beta01 ) locally and it's works well.
    My config file (example.com.conf):

    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    #server {
    #            listen   80;
    #            server_name example.com;
    #            return 301 $scheme://www.example.com$request_uri;
    #       }
    
    server {
     
      server_name example.com www.example.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/example.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/example.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/example.com/autoprotect-example.com.conf;
      root /home/nginx/domains/example.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      #include /usr/local/nginx/conf/503include-main.conf;
    
    # Common #
    
    location ~ ^/sites/.*/private/ {
      return 403;
    }
    
    # Block access to hidden files and directories (begin with a period).
    location ~ (^|/)\. {
      return 403;
    }
    location ~* ^(?:.+\.(?:htaccess|make|txt|engine|inc|info|install|module|profile|po|pot|sh|twig|scss|.*sql|test|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ {
      return 404;
    }
    # Dont allow direct access to composer and yml files
    location ~* /(.*)\.(?:yaml|yml|lock|json)$ {
      deny all;
      access_log off;
      log_not_found off;
    }
    
    # Dont allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
      deny all;
      return 404;
    }
    
    location ^~ \.(png|jpg|jpeg|gif|ico|woff|woff2|svg)$ {
      expires max;
      log_not_found off;
    }
    
    gzip on;
    gzip_comp_level 5;
    gzip_disable "msie6";
    gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
    
    # Drupal #
    # Update script
    rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;
    # Remove trailing slash.
    rewrite ^/(.*)/$ /$1 permanent;
    # Styles.
    location ~ ^/sites/.*/files/styles/ {
      expires max;
      try_files $uri @rewrite;
      log_not_found off;
    }
    
    # Private files through Drupal.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
      try_files $uri /index.php?$query_string;
    }
    
    # Cache Files.
    location ~ ^/sites/.*/files/ {
      expires 30d;
      log_not_found off;
    }
    
    # Cache Core/Libs/Contrib
    location ~ /(core|libraries|modules/contrib)/.*\.(css|js|png|jpg|jpeg|gif|ico|woff|woff2|svg) {
      add_header Cache-Control public;
      expires     10d;
    }
    
    # Cache Theme CSS/JS
    location ~ /themes/.*\.(css|js)$ {
      etag off;
      log_not_found off;
    }
    
    # Custom Modules
    location ~ /modules/custom/.*\.(css|js)$ {
      etag off;
      log_not_found off;
    }
    
    # Cache Theme Images/Fonts
    location ~ /themes/.*\.(png|jpg|jpeg|gif|ico|woff|woff2|svg)$ {
      expires 30d;
      log_not_found off;
    }
    
    # letsencrypt #
     location ~* ^/.well-known/ {
            allow all;
      }
    
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
     
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    

    What should be added or removed from the file?

    I can install themes, modules, run update..., but I would like to have a configuration for Drupal 8 "on the right way".

    Thanks.
     
  2. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    5:25 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    no drupal experience either but you can check other threads for clues Blogs & CMS usage
     
..