Verdaccio 私服搭建nginx反向代理配置


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen 80;
        return 302 https://$host$request_uri;
    }

    server {
        listen       443 ssl http2;
        # server_name 指定为域名 例如:baidu.com key.baidu.com
        server_name  verdaccio;

        access_log logs/verdaccio.log;
        charset utf-8;
        
        ssl_certificate      /verdaccio.pem;
        ssl_certificate_key  /verdaccio.key;
        
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

        location / {
           # 真实发出请求的客户端IP
           proxy_set_header X-Real-IP $remote_addr; 
           # 记录代理信息,每经过一级代理(匿名代理除外),代理服务器都会把这次请求的来源IP追加在X-Forwarded-For中
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           # $host变量的值按照如下优先级获得:
				# 请求行中的host.
				# 请求头中的Host头部.
				# 与一条请求匹配的server name.
           proxy_set_header Host $host;
           # 用于识别协议(HTTP 或 HTTPS),其中使用的客户端连接到代理或负载平衡器一个真实的标准报头
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_pass http://localhost:4873;
           # off参数取消proxy_redirect从先前配置级别继承的指令的效果
           proxy_redirect off;
        }
    }
}

ngx_http_proxy_module

上一篇:Teach Yourself SQL in 10 Minutes – Page 31 练习


下一篇:6 反身代词