Nginx的HTTPS多域名配置和websocket转发配置

内容目录

Nginx 配置HTTPS和websocket的方法

websocket的相关配置:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 4s; 
proxy_read_timeout 7200s; 
proxy_send_timeout 12s;
 upstream websocket-project{
         server localhost:8080;

    }

server {
            listen 443 ssl;
            listen    [::]:443 ssl;
            server_name websocket.yhbsoul.com;
            ssl on;
            ssl_certificate   certificate.pem;
            ssl_certificate_key  private.key;
            ssl_session_timeout 5m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_prefer_server_ciphers on;    

          location / {
               #include agent_deny.conf;
               proxy_pass http://websocket-project;

               proxy_set_header Host $host;
               proxy_http_version 1.1;
               proxy_set_header X-Client-IP $remote_addr;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection "upgrade";
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_connect_timeout 4s; 
               proxy_read_timeout 7200s; 
               proxy_send_timeout 12s; 

          }
          location ~ ^/(/)?.* {
               #include agent_deny.conf;
               proxy_pass http://websocket-project;

               proxy_set_header Host $host;
               proxy_http_version 1.1;
               proxy_set_header X-Client-IP $remote_addr;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection "upgrade";
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_connect_timeout 4s; 
               proxy_read_timeout 7200s; 
               proxy_send_timeout 12s; 
          }

     }

多个HTTPS域名配置时,将其server 复制出多份。修改其中server_name 为对应的HTTPS域名即可实现。

  • 海报
  • 打赏
  • 分享
海报图正在生成中...
分享到...
请选择打赏方式
  • 微信
  • 支付宝

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注