美文网首页
【nginx】 nginx 接口代理、端口代理配置

【nginx】 nginx 接口代理、端口代理配置

作者: Bogon | 来源:发表于2022-12-07 00:12 被阅读0次

接口代理 (无需单独映射端口)

注意: 被代理接口,不能和原系统接口冲突了

访问链路: 客户端 -->https://www.example.com:443/xxx --->http://xx.xx.xx.xx:8080

    location ^~ /xxx  {
        proxy_pass http://xx.xx.xx.xx:8080;
        proxy_set_header Host $http_host;
        proxy_set_header x-request-rid $request_id;
        proxy_set_header remote_scheme $scheme;
        #proxy_set_header remote_scheme https;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        #proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Accept-Encoding "";
        proxy_redirect   http://$host https://$host;
    }

端口代理(需单独映射端口)

注意:在接入层nginx主配置中加一个 server 块,此处并不是做stream转发

访问链路: 客户端 -->https://www.example.com:3333 --→http://xx.xx.xx.xx:3333

server {
        listen  3333 ssl;
        server_name  www.example.com.com;

        ssl_certificate       rapidssl/www.example.com.pem;
        ssl_certificate_key   rapidssl/www.example.com.key;
        ssl_dhparam           rapidssl/dhparams.pem;

        ssl_session_timeout  5m;
        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES';
        ssl_prefer_server_ciphers on;
        add_header Strict-Transport-Security max-age=15768000;

location / {
        proxy_pass http://xx.xx.xx.xx:3333;
        proxy_set_header Host $http_host;
        proxy_set_header x-request-rid $request_id;
        proxy_set_header remote_scheme $scheme;
        #proxy_set_header remote_scheme https;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        #proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Accept-Encoding "";
        proxy_redirect   http://$host https://$host;
 }

}

相关文章

网友评论

      本文标题:【nginx】 nginx 接口代理、端口代理配置

      本文链接:https://www.haomeiwen.com/subject/ciqifdtx.html