0

I am trying to get a websocket client connected to my server with a ssl connection. I want to reach it with www.myurl.com/socket/ (subdomains would also be an option) and the websocket server is running on port 7777. As the server is running Plesk I need to do the configuration in the Plesk Interface.

What I just tried is to place my configuration here: Apache & nginx Settings for myurl | Additional nginx directives

My config is as follows:

location /socket/ {
    proxy_pass "http://127.0.0.1:7777";
    proxy_read_timeout     60;
    proxy_connect_timeout  60;
    proxy_redirect         off;
    # Allow the use of websockets
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

}

I don't get any connection established. It worked without des proxy_pass on non secured connection.

Did I place the config wrong or any other hint what the problem could be? It would also help me if there are useful methods or tools to analyze where the error is.

Constantin
  • 3
  • 1
  • 2

1 Answers1

0

Ensure that

  1. Your DNS is pointing to your NGINX IP
  2. Your server block is configured under /etc/nginx/sites-available/myurl.com
  3. You have a soft link to enable to site : ln -s /etc/nginx/sites-available/myurl.com /etc/nginx/sites-enabled
  4. Validate the nginx config with nginx -t
  5. Restart the nginx service when making changes service nginx restart

You have a lot of options in your config which you may not need. I suggest simplifying it to see if the basic works.

    server { 
          server_name myurl.com;
                  location / {
                           proxy_pass http://127.0.0.1:7777;
                  }
    }

Try to access http://myurl.com/socket If it doesn't work try adding the 'www' or '/socket' in the server config. Only once you get it working with http, then add SSL certificate parameters afterwards.

server {
        server_name myurl.com;
        location /socket {
                proxy_pass http://127.0.0.1:7777/socket;
        }
        location / {
                proxy_pass http://127.0.0.1:7777;
        }
        listen [::]:443 ssl;
        listen 443 ssl;
        ssl_certificate /etc/ssl/ssl.crt;
        ssl_certificate_key /etc/ssl/ssl.key;
}
server {
    if ($host = myurl.com) {
        return 301 https://$host/;
    }
        listen 80;
        listen [::]:80;

        server_name myurl.com;
    return 404;
}
madacoda
  • 215
  • 1
  • 9
  • 1
    As im running a Plesk Server the files are in /var/www/vhosts/system/myurl.com/conf/ divided in nginx.conf (which is written by Plesk) and vhosts_nginx.conf where additional conf can be placed (Same as in Additional nginx directives in the GUI). As Plesk overwrites the conf file I couldn't try your simplified config. I just created a subdomain and placed the config there. Here I could test the proxy_pass for the whole subdomain. And at the end my initial config worked, whyever. Thanks for your help! – Constantin Apr 30 '20 at 19:10