Nginx常用配置

nginxhosterfeatured.jpg

GZIP配置

    gzip  on;  
    gzip_min_length  1000;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_disable     "msie6";
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_http_version 1.0;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;  

HTTPS & HTTP2

    listen	 443 ssl http2 fastopen=3 reuseport;
    server_name  xxx.com www.xxx.com;
    server_tokens off;  
	
    ssl_certificate      /etc/nginx/certs/xxx.com.crt;
    ssl_certificate_key  /etc/nginx/certs/xxx.com.key;  
    ssl_session_cache    shared:SSL:50m;
    ssl_session_timeout  1d;
    ssl_session_tickets  on;
    ssl_stapling	 on;
    ssl_stapling_verify  on;

    # enable HSTS
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";

    # redirect www to none www
    if ($http_host !~ "^xxx.com") {
	return 301 https://xxx.com$request_uri;
    }