Popular blog tags

Introduction

# nginx -v
nginx version: nginx/1.14.0 (Ubuntu)

/etc/nginx/sites-enabled/default.conf

server {
	               listen 80; # managed by Certbot	
              server_name   *.demo.com;	
	location / {
                             error_log /var/log/nginx/error.log;
                             proxy_pass http://hostserver;
    
                              proxy_set_header Host $host;

                              proxy_set_header X_Real_IP $remote_addr;
                            
                             proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                             proxy_set_header        X-Forwarded-Proto $scheme;
                             
                             add_header       X-Test $remote_addr;

                            
	}

}

Error message

# nginx -t
nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

Add 

   proxy_headers_hash_max_size 512;
  proxy_headers_hash_bucket_size 128;          

 

server {
	               listen 80; # managed by Certbot	
              server_name   *.demo.com;	
	location / {
                             error_log /var/log/nginx/error.log;
                             proxy_pass http://hostserver;
    
                              proxy_set_header Host $host;

                              proxy_set_header X_Real_IP $remote_addr;
                            
                             proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                             proxy_set_header        X-Forwarded-Proto $scheme;
                             
                             add_header       X-Test $remote_addr;
                                    #come from:https://www.iaspnetcore.com/blog/5f8b1dabf3819901eefd49e5
                                 # nginx -t
                              #nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
                              #add  below
                              proxy_headers_hash_max_size 512;
                              proxy_headers_hash_bucket_size 128;          
	}

}

After you are done editing the small part, check your Nginx configuration by running the nginx -t command.

sudo nginx -t 

You should get:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful