V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
oxogenesis
V2EX  ›  NGINX

Nginx 配置求助,如何讲 wss 和 https 同时指向一个域名

  •  
  •   oxogenesis ·
    oxogenesis · 2020-06-16 15:16:09 +08:00 · 1355 次点击
    这是一个创建于 1639 天前的主题,其中的信息可能已经有所发展或是发生改变。
    当前配置见
    https://github.com/oxogenesis/oxo-chat-server

    https 指向 https://oxo-chat-server.com
    wss 指向 wss://ru.oxo-chat-server.com

    问题:如何把两者都指向 ru.oxo-chat-server.com
    谢谢!
    oxogenesis
        2
    oxogenesis  
    OP
       2020-06-16 15:54:11 +08:00
    server {
    listen 443 ssl;
    server_name ru.oxo-chat-server.com;
    ssl_certificate /etc/letsencrypt/live/ru.oxo-chat-server.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ru.oxo-chat-server.com/privkey.pem;
    ssl_protocols TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
    try_files /nonexistent @$http_upgrade;
    }

    location @websocket {
    proxy_pass http://localhost:3000/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_connect_timeout 1d;
    proxy_send_timeout 1d;
    proxy_read_timeout 1d;
    }

    location @ {
    proxy_pass http://localhost:8000/;
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forward-Proto http;
    proxy_set_header X-Nginx-Proxy true;
    proxy_redirect off;
    }
    }

    server {
    listen 80;
    server_name ru.oxo-chat-server.com;
    return 301 https://$host$request_uri;
    }



    # nginx -t
    nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/sites-enabled/default:19
    nginx: configuration file /etc/nginx/nginx.conf test failed
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4430 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 03:56 · PVG 11:56 · LAX 19:56 · JFK 22:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.