Drupal auf NGINX

NGINX

Kompilieren

./configure --prefix=/home/<USER> --sbin-path=/home/<USER>/bin/nginx
--conf-path=/home/<USER>/etc/nginx/nginx.conf --pid-path=/home/<USER>/var/run/nginx.pid --error-log-path=/home/<USER>/var/log/nginx/error.log --http-log-path=/home/<USER>/var/log/nginx/access.log --lock-path=/home/<USER>/var/run/nginx.lock --http-client-body-temp-path=/home/<USER>/tmp/nginx/client/ --http-proxy-temp-path=/home/<USER>/tmp/nginx/proxy/ --http-fastcgi-temp-path=/home/<USER>/tmp/nginx/fastcgi --with-http_flv_module --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --with-mail --with-mail_ssl_module --http-uwsgi-temp-path=/home/<USER>/tmp/nginx/uwsgi/ --http-scgi-temp-path=/home/<USER>/tmp/nginx/scgi/ --with-file-aio --without-http_uwsgi_module --without-http_scgi_module --with-pcre

Konfiguration

I use a cloudserver from webfaction.com (2GB Memory, 2x CPU's). They have a frontend "nginx" and I running my customer "nginx" behind. Here is my config file for my drupal8 site:

# System
worker_processes  2;

events {
    worker_connections  1024;
}

http {
    include             mime.types;
    default_type        application/octet-stream;
    sendfile            on;
    server_tokens       on;
    keepalive_timeout   0;
    # GZIP
    gzip  on;
    gzip_http_version  1.1;
    gzip_comp_level    5;
    gzip_proxied       any;
    gzip_vary          on;
    gzip_types
      application/atom+xml
      application/javascript
      application/json
      application/rss+xml
      application/vnd.ms-fontobject
      application/x-font-ttf
      application/x-web-app-manifest+json
      application/xhtml+xml
      application/xml
      font/opentype
      image/svg+xml
      image/x-icon
      text/css
      text/plain
      text/x-component;

    server {
       listen <PORT>;
        server_name example.com;
        return 301 https://www.example.com$request_uri;
    }

    server {
        listen      <PORT>;
        server_name www.example.com
        charset     utf-8;
        root        /home/<USERNAME>/var/www/example.com/live;
        index       index.php index.html;
        # Location
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
        location ~ \..*/.*\.php$ {
            return 403;
        }
        location ~ (^|/)\. {
            return 403;
        }
        location ^~ /vendor/ {
            deny all;
            return 404;
        }
        location ~ ^/sites/.*/private/ {
            access_log off;
            deny all;
        }
        location / {
            try_files $uri /index.php?$query_string;
        }
        location @rewrite {
            rewrite ^/(.*)$ /index.php?q=$1;
        }
        # PHP
        location ~ \.php(/|$) {
            fastcgi_pass unix:/home/loteknginx/var/run/fpm1.sock;
            access_log off;
            proxy_set_header X-Forwarded-Proto https;
            fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
            include fastcgi_params;    
            fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_intercept_errors on;
        }
        # Fighting with Styles? This little gem is amazing.
        location ~ ^/sites/.*/files/styles/ { # For Drpal >= 7
            try_files $uri @rewrite;
        }
        # Caching
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
            expires max;
            access_log off;
            log_not_found off;
        }
    }
}