1

I have the following problem. I try to create a .NET Core Web-API and a Vue-SPA frontend.

For this purpose I´m using Nginx as a server on my windows machine.

For this .NET generate a SSL-certificate for me. This was generated in the certmgr in the folder own certificates.

To generate the certificate for Nginx I exported this generated file and follow this guid to transform it.

https://blog.knoldus.com/easiest-way-to-setup-ssl-on-nginx-using-pfx-files/

So I got my cert.crt and cert.rsa. Both off them I am using for Ngnix. Everything work fine for the Web-API. But on the frontend i alway get the following error

sockjs.js?9be2:1605 GET https://192.168.178.145:8081/sockjs-node/info?t=1552754433422 net::ERR_CERT_COMMON_NAME_INVALID

So the webpack-dev-server have trouble to connect. But I dont figure out why. What I am doing wrong in this case?

This is my Nginx config

server {
        listen       58000 ssl;
        server_name  localhost;

        ssl_certificate      domain.crt;
        ssl_certificate_key  domain.rsa;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            #proxy_buffering    off;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   Host      $host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass https://localhost:8081/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        location /api {
            proxy_pass https://127.0.0.1:5001;
        }
    }

And in my webpack-dev-server I am using the following

module.exports = {
    devServer: {
      https: {
        key: fs.readFileSync('path\\domain.rsa'),
        cert: fs.readFileSync('path\\domain.crt'),
      }
    }
  }

So it´s for me it´s look like that there are some issues with the certificate. But why is it only failing on the websockets and not on the rest?

Sorry I´m new to SSL and Nginx.

Darem
  • 1,689
  • 1
  • 17
  • 37

1 Answers1

3

sockjs.js?9be2:1605 GET https://192.168.178.145:8081/sockjs-node/info?t=1552754433422 net::ERR_CERT_COMMON_NAME_INVALID

This shows that you are using 192.168.178.145 as the hostname

    server_name  localhost;

This shows that nginx expects localhost as hostname

    ssl_certificate      domain.crt;

It is unclear what the really name you have configured in the certificate but it is very likely that it is not 192.168.178.145. Thus the error.

    listen       58000 ssl;

And this shows that your nginx is listening on port 5800. The URL from the error message is instead for port 8081. This might indicate that the nginx configuration you show has nothing to do with the server which gets actually accessed - I have no idea what server is on port 8081.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • Thx for the response on the port 8081 is running my Frontend Node-Server and Nginx is running on Port 58000 so I thought when Port 58000 is accessed Nginx is passed to 8081? – Darem Mar 16 '19 at 17:38
  • @Darem: If you access port 8081 it will only access port 8081. The nginx on port 58000 is not involved in this. – Steffen Ullrich Mar 16 '19 at 18:25
  • thank you very much. It solved my problem in renaming the dev server to localhost. So now it works. Thank you very much! – Darem Mar 17 '19 at 08:57
  • @SteffenUllrich would you be so kind in helping to solve my similar problem? https://stackoverflow.com/questions/59883945/get-err-ssl-protocol-error-nginx-vue-js – user2315094 Jan 23 '20 at 17:21
  • For Vue on webpack dev server, this solution: https://stackoverflow.com/a/66701328/1207540 helped me. – Glen Mazza Jun 21 '21 at 12:38