简体   繁体   中英

wss://my.domain.com/sockjs/362/4q059yw7/websocket

I need help in fixing this issue.

I am trying to implement ssl to the domain my.domain.com

Front end is Angular and Backend is Meteor

I was able to create ssl certificates properly and was able to get Secure https label on loading the domain, but the page was not rendering because of the error

Uncaught TypeError: a._qs.unescape is not a function

from the build file in the .build/dist/bundle/programs/web.browser

Request URL:https://my.domain.com/5a0c202b90aa3cc1c9414b703c4e1f343fb0dd4e.js?meteor_js_resource=true

Below websocket request will remain pending with status 101

wss://my.domain.com/sockjs/362/4q059yw7/websocket

I have not written any code on Meteor to run it to https, I am trying to handle through nginx. From angular after adding ssl certificates trying to connect to meteor through wss://localhost/ instead of ws://localhost:3000/

Please find my nginx file below.

events {    
}

http {
  server {
     listen 80;
     listen [::]:80 default_server ipv6only=on;
     server_name  my.domain.com;
     root   /client;
     index  index.html;

     location / {
        rewrite     ^ https://$server_name$request_uri? permanent;
     }
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

 server {
    # Enable HTTP/2
     listen 443 ssl http2;
     listen [::]:443 ssl http2;
     server_name  my.domain.com;

     root   /client;
     index  index.html;
     ssl_certificate /etc/letsencrypt/live/my.domain.com/fullchain.pem; # managed by Certbot
     ssl_certificate_key /etc/letsencrypt/live/my.domain.com/privkey.pem; # managed by Certbot
     ssl_dhparam /etc/ssl/certs/dhparam.pem;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; # allow websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    location /api {
        proxy_pass http://localhost:3000;
    }

    location /uploadFile {
        proxy_pass http://localhost:3000;
    }

    error_page   500 502 503 504  /50x.html;
    location = /51x.html {
        root   /client;
    }
  }  
}

Any leads would be appreciated.

I figured out the issue I had. Issue was in below line in nginx.

 proxy_pass http://localhost:3000;

I fixed it by redirecting it to http://localhost:3000/websocket; and location as location /websocket

Snippet is below.

location /websocket {
   proxy_pass http://localhost:3000/websocket;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade; # allow websockets
   proxy_set_header Connection $connection_upgrade;
   proxy_set_header X-Forwarded-For $remote_addr;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM