Sign inSign up

leadingfellows/nginx-drupal

By leadingfellows

•Updated 5 months ago

Nginx container for Drupal with custom config based on env variables

Image
1

1.1K

leadingfellows/nginx-drupal repository overview

⁠nginx-drupal

Nginx container pre-configured for running a Drupal 8 website This will create a single vhost with a filesystem root to be served and an upstream phpfpm backend running on an another host or container

Typical environment variables to set:

⁠Reference :

⁠NGINX Configuration

user                            {{ getenv "NGINX_USER" "nginx" }};
worker_processes                {{ getenv "NGINX_WORKER_PROCESSES" "auto" }};
error_log                       /proc/self/fd/2 {{ getenv "NGINX_ERROR_LOG_LEVEL" "error" }};
    worker_connections          {{ getenv "NGINX_WORKER_CONNECTIONS" "1024" }};
    multi_accept                {{ getenv "NGINX_MULTI_ACCEPT" "on" }};
    {{ if getenv "NGINX_LOG_FORMAT_OVERRIDE" }}
    log_format                  combined '{{ getenv "NGINX_LOG_FORMAT_OVERRIDE" }}';
    {{ end }}
    access_log                  /proc/self/fd/1 {{ if getenv "NGINX_LOG_FORMAT_SHOW_REAL_IP" }}real_ip{{ else }}combined{{ end }};
    send_timeout                {{ getenv "NGINX_SEND_TIMEOUT" "60s" }};
    sendfile                    {{ getenv "NGINX_SENDFILE" "on" }};
    client_body_timeout         {{ getenv "NGINX_CLIENT_BODY_TIMEOUT" "60s" }};
    client_header_timeout       {{ getenv "NGINX_CLIENT_HEADER_TIMEOUT" "60s" }};
    client_max_body_size        {{ getenv "NGINX_CLIENT_MAX_BODY_SIZE" "32m" }};
    client_body_buffer_size     {{ getenv "NGINX_CLIENT_BODY_BUFFER_SIZE" "16k" }};
    client_header_buffer_size   {{ getenv "NGINX_CLIENT_HEADER_BUFFER_SIZE" "4k" }};
    large_client_header_buffers {{ getenv "NGINX_LARGE_CLIENT_HEADER_BUFFERS" "8 16K" }};
    keepalive_timeout           {{ getenv "NGINX_KEEPALIVE_TIMEOUT" "75s" }};
    keepalive_requests          {{ getenv "NGINX_KEEPALIVE_REQUESTS" "100" }};
    reset_timedout_connection   {{ getenv "NGINX_RESET_TIMEDOUT_CONNECTION" "off" }};
    tcp_nodelay                 {{ getenv "NGINX_TCP_NODELAY" "on" }};
    tcp_nopush                  {{ getenv "NGINX_TCP_NOPUSH" "on" }};
    types_hash_max_size         {{ getenv "NGINX_TYPES_HASH_MAX_SIZE" "2048" }};
    server_tokens               {{ getenv "NGINX_SERVER_TOKENS" "off" }};
    server_names_hash_bucket_size {{ getenv "NGINX_SERVER_NAMES_HASH_BUCKET_SIZE" "128" }};
    #upload_progress             {{ getenv "NGINX_UPLOAD_PROGRESS" "uploads 1m" }};
    gzip                        {{ getenv "NGINX_GZIP" "on" }};
    gzip_buffers                {{ getenv "NGINX_GZIP_BUFFERS" "16 8k" }};
    gzip_comp_level             {{ getenv "NGINX_GZIP_COMP_LEVEL" "1" }};
    gzip_http_version           {{ getenv "NGINX_GZIP_HTTP_VERSION" "1.1" }};
    gzip_min_length             {{ getenv "NGINX_GZIP_MIN_LENGTH" "20" }};
    gzip_vary                   {{ getenv "NGINX_GZIP_VARY" "on" }};
    gzip_proxied                {{ getenv "NGINX_GZIP_PROXIED" "any" }};
    gzip_disable                {{ getenv "NGINX_GZIP_DISABLE" "msie6" }};
    {{ if not (getenv "NGINX_NO_DEFAULT_HEADERS") }}
    add_header                  X-XSS-Protection '1; mode=block';
    add_header                  X-Frame-Options SAMEORIGIN;
    add_header                  X-Content-Type-Options nosniff;
    {{ end }}
    include {{ getenv "NGINX_CONF_INCLUDE" "conf.d/*.conf" }};

⁠Vhost configuration

    server {{ getenv "NGINX_BACKEND_HOST" "php"}}:{{ getenv "NGINX_BACKEND_HOST_PORT" "9000"};
    server_name {{ getenv "NGINX_SERVER_NAME" "drupal" }};
    root {{ getenv "NGINX_SERVER_ROOT" "/var/www/html/" }};
    client_max_body_size {{ getenv "NGINX_CLIENT_BODY_MAX_SIZE" "200M" }};
    gzip_static {{ getenv "NGINX_GZIP_STATIC" "on" }};
{{ if getenv "NGINX_DRUPAL_HIDE_HEADERS" }}
    fastcgi_hide_header 'X-Drupal-Cache';
    fastcgi_hide_header 'X-Generator';
    fastcgi_hide_header 'X-Drupal-Dynamic-Cache';
{{ end }}
{{ if getenv "NGINX_DRUPAL_FILE_PROXY_URL" }}
        location ~* /sites/.+/files {
            try_files $uri @file_proxy;
        }
{{ end }}


            access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
            expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};
            access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
            expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};
            open_file_cache {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE" "max=3000 inactive=120s" }};
            open_file_cache_valid {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE_VALID" "45s" }};
            open_file_cache_min_uses {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE_MIN_USES" "2" }};
                access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
                access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
{{ if getenv "NGINX_ALLOW_XML_ENDPOINTS" }}
        location ~* ^.+\.xml {
            try_files $uri @drupal;
        }
{{ else }}
        location ~* /rss.xml {
            try_files $uri @drupal-no-args;
        }

        location ~* /sitemap.xml {
            try_files $uri @drupal;
        }
{{ end }}
            access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
            expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};
            open_file_cache {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE" "max=3000 inactive=120s" }};
            open_file_cache_valid {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE_VALID" "45s" }};
            open_file_cache_min_uses {{ getenv "NGINX_STATIC_CONTENT_OPEN_FILE_CACHE_MIN_USES" "2" }};
        #    expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};
{{ if getenv "NGINX_DRUPAL_FILE_PROXY_URL" }}
    location @file_proxy {
        rewrite ^ {{ getenv "NGINX_DRUPAL_FILE_PROXY_URL" }}$request_uri? permanent;
    }
{{ end }}
        #track_uploads {{ getenv "NGINX_DRUPAL_TRACK_UPLOADS" "uploads 60s" }};
{{ if getenv "NGINX_DRUPAL_DENY_ACCESS_UPDATE_PHP" }}
    return 404;
{{ else }}
        include fastcgi.conf;
        fastcgi_param QUERY_STRING $args;
        fastcgi_param SCRIPT_NAME /update.php;
        fastcgi_param SCRIPT_FILENAME $document_root/update.php;
        fastcgi_pass php;

{{ end }} 
        access_log {{ getenv "NGINX_STATIC_CONTENT_ACCESS_LOG" "off" }};
        log_not_found {{ getenv "NGINX_ROBOTS_TXT_LOG_NOT_FOUND" "off" }};
        expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};
        expires {{ getenv "NGINX_STATIC_CONTENT_EXPIRES" "30d" }};

{{ if getenv "NGINX_SERVER_EXTRA_CONF_FILEPATH" }}
    include {{ getenv "NGINX_SERVER_EXTRA_CONF_FILEPATH" }};
{{ end }}

Tag summary

Content type

Image

Digest

sha256:c139f1886…

Size

32.7 MB

Last updated

5 months ago

docker pull leadingfellows/nginx-drupal