SatelliteWP / rocket-nginx

Rocket-Nginx is a Nginx configuration that makes WP-Rocket even faster by serving static pages directly without loading WordPress or PHP.
MIT License
579 stars 129 forks source link

nginx: [warn] could not build optimal variables_hash, you should increase either variables_hash_max_size: 1024 or variables_hash_bucket_size: 64; ignoring variables_hash_bucket_size #177

Closed Squeezemind closed 2 years ago

Squeezemind commented 2 years ago

Hi guys, when I include your default.conf, nginx -t tells me:

nginx: [warn] could not build optimal variables_hash, you should increase either variables_hash_max_size: 1024 or variables_hash_bucket_size: 64; ignoring variables_hash_bucket_size

this is my nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 4096;
    multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

        map $http_x_forwarded_proto $fastcgi_param_https_variable {
                default '';
                https 'on';
        }

        #sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 5;
        types_hash_max_size 2048;
        # server_tokens off;

        server_names_hash_bucket_size 512;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

    autoindex           off;
    server_tokens       off;
    port_in_redirect    off;
    sendfile            on;
    etag                off;

    client_max_body_size 64m;
    client_body_buffer_size 128k;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 16k;

    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;

    ## Flood protection example (see conf_m2/extra_protect.conf)
    limit_req_zone $binary_remote_addr zone=zone1:35m rate=1r/s;
    limit_req_zone $binary_remote_addr zone=zone2:35m rate=1r/s;
    limit_req_zone $binary_remote_addr zone=zone3:35m rate=1r/s;

    ## Cache open FD
    open_file_cache max=35000 inactive=30s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;

    ## Gzipping is an easy way to reduce page weight
    gzip                on;
    gzip_vary           on;
    gzip_proxied        any;
    gzip_types          application/javascript application/x-javascript application/rss+xml text/javascript text/css text/plain image/x-icon image/svg+xml;
    gzip_buffers        4 16k;
    gzip_comp_level     6;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

This is the website conf:

server {

    listen 80;

    server_name example.com www.example.com;

    # Redirect HTTP to HTTPS
    return 301 https://$host$request_uri;

}

server {

    listen 443 ssl http2;

    server_name example.com www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    root /var/www/example.com/public_html/;
    index index.php index.html index.htm;

    #access_log /var/www/example.com/logs/access.log;
    error_log /var/www/example.com/logs/error.log;

    # Rocket-Nginx configuration
    include /etc/nginx/rocket-nginx/conf.d/default.conf;

    location ~* \.(eot|ttf|woff|woff2)$ {
        add_header Access-Control-Allow-Origin *;
        expires 365d;
        access_log off;
        log_not_found off;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|webp)$ {
        expires 365d;
        access_log off;
        log_not_found off;
    }

    location / {
      try_files $uri $uri/ /index.php?$args;
      error_page 405 = $uri;
    }

    location /staging{

        try_files $uri $uri/ /staging/index.php?$args;

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_read_timeout 300s;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.4-fpm-example.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                include fastcgi_params;
        }

    }

    location /phpmyadmin {

        auth_basic "Admin Login";
        auth_basic_user_file /etc/phpmyadmin/authbasic.passwd;

        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
                try_files $uri =404;
                root /usr/share/;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                include fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                root /usr/share/;
        }
    }

    location = /xmlrpc.php {
        deny all;
        access_log off;
        log_not_found off;
        return 444;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_read_timeout 300s;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm-example.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }

}
maximejobin commented 2 years ago

Well, the error seems self-explanatory. You need to modify your configuration to increase some values.

Please see the Nginx configuration page for more information: http://nginx.org/en/docs/http/ngx_http_core_module.html#variables_hash_bucket_size