nginx.conf配置

user  www www;

worker_processes auto;
worker_cpu_affinity auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
    {
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile on;
        sendfile_max_chunk 512k;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

        proxy_connect_timeout 15;
        proxy_read_timeout 60s;
        proxy_send_timeout 12s;
        proxy_buffer_size 64k;
        proxy_buffers 4 64k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 256k;
        proxy_max_temp_file_size 2048m;
        proxy_cache_path /home/www_cache levels=1:2 keys_zone=www_cache:10m max_size=10g;
        proxy_cache_key "$host$request_uri";
        proxy_temp_path /home/tmp;

        proxy_redirect          off;
        proxy_set_header Host   $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

map $http_upgrade $connection_upgrade
    {
        default upgrade;
        '' close;
    }
    
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

upstream www
{
        server 127.0.0.1:443 weight=2 max_fails=2 fail_timeout=30s;
        server [::1]:443 weight=1 max_fails=2 fail_timeout=30s;
        keepalive 300;
}

server
    {
        listen 80 default_server reuseport;
        listen [::]:80 default_server ipv6only=on;
        server_name _;

        rewrite ^(.*) http://127.0.0.1 permanent;

        access_log  /home/wwwlogs/access.log;
    }
include vhost/*.conf;
}

vhost.conf配置

server
    {
        listen 80;
        listen [::]:80;
        server_name czgblog.com www.czgblog.com;
        
        rewrite ^(.*) https://www.czgblog.com$1 permanent;

        access_log  /home/wwwlogs/czgblog.com.log;
    }

server
    {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name czgblog.com www.czgblog.com;
        
        ssl_certificate /usr/local/nginx/conf/ssl/czgblog.com.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/czgblog.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

        location / {
            proxy_pass              https://www;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
        {
            expires      30d;
            proxy_pass              https://www;
            proxy_cache www_cache;
            proxy_cache_key %s$request_uri$is_args$args;
            proxy_cache_valid 200 304 301 302 24h;
            proxy_cache_min_uses 3;
        proxy_next_upstream http_500 http_502 http_503 http_504 http_429 error timeout invalid_header;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
            proxy_pass              https://www;
            proxy_cache www_cache;
            proxy_cache_key %s$request_uri$is_args$args;
            proxy_cache_valid 200 304 301 302 24h;
            proxy_cache_min_uses 3;
        proxy_next_upstream http_500 http_502 http_503 http_504 http_429 error timeout invalid_header;
        }

        access_log  /home/wwwlogs/czgblog.com.log;
    }

标签: nginx, 反向代理, 缓存

添加新评论