分享下nginx配置HTTPS WSS

Alu

困扰了我一天,总算解决了,分享下;
使用的是阿里云免费证书,服务器使用的是nginx;

关键点是:

location /wss/
{
    proxy_pass http://127.0.0.1:7070;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    rewrite /wss/(.*) /$1 break;
    proxy_redirect off;
}

那么你的WSS连接地址是:域名或IP/wss/

workerman 连接端口是:127.0.0.1:1010;

  server {

    listen 443 ssl http2 default_server;
        server_name xwmm;

        ssl_certificate      key/xwmm.pem;
        ssl_certificate_key  key/xwmm.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
        ssl_prefer_server_ciphers  on;

    index index.html index.htm index.php;
    root /home/xwmm;

    location /wss/
    {
            proxy_pass http://127.0.0.1:1010;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            rewrite /wss/(.*) /$1 break;
            proxy_redirect off;
    }

    location ~ .*\.(php|php5)?$
    {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
            expires 30d;
    }
    location ~ .*\.(js|css)?$
    {
            expires 1h;
    }
    #伪静态规则
    include /home/nginx/conf/rewrite/xwmm.conf;
    access_log  /log/nginx/access/xwmm.log;

   }

   server {
    listen 80;
    server_name xwmm;
    rewrite ^(.*) https : //$server_name$1 permanent;
   }
19717 6 4
6个回答

walkor 打赏

感谢分享

jelson1028

这边也需要使用,直接使用上面的配置进行更改,可以生效。
感谢感谢

  • 暂无评论
keytehu

非常感谢,正是我需要的

  • 暂无评论
jinnstyl

很有用,非常感谢!

  • 暂无评论
simba222

感谢分享,正好准备在服务器上配置这一块

  • 暂无评论
mrliuuu

非常感谢

  • 暂无评论
年代过于久远,无法发表回答
×
🔝