# How to use SSL with NGnix

**URL:** <https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403>\
**Category:** Product Support\
**Created:** [July 1, 2019, 8:41pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403 "2019-07-01T20:41:11Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 1, 2019, 8:41pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/1 "2019-07-01T20:41:12Z")

</div>

So here is my issue.

internet \<- AudioCodes SBC -\> OpenNebula 5.8.2 \<-\> Nodes

A the beginning, everything worked correctly.  
Then we decided to use SSL connections.  
So the SBC now forward port 443 to NGINX@OpenNebula:443  
We can connect. The only issue is with the VNC no coming up.

```
root@boson:/etc> more nginx/conf.d/default.conf
#### OpenNebula Sunstone Upstream
upstream sunstone {
		server 127.0.0.1:9869;
		}

		
server {
        listen 443 ssl;
        server_name xyz.com;

        ### SSL Parameters
        #ssl on;
        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

        ### Proxy requests to upstream
        location / {
                 proxy_pass http://sunstone;
        }

}

```

And my sunstone-server vnc configuration:  
:vnc\_proxy\_port: 29876  
:vnc\_proxy\_support\_wss: no  
:vnc\_proxy\_cert:  
:vnc\_proxy\_key:  
:vnc\_proxy\_ipv6: false  
:vnc\_request\_password: false

Is there anything else to do ?

I can connect to the Sunstone GUI, but if I request a VNC, all I get is this:  
`##### VNC noVNC ready: native WebSockets, canvas rendering`

---

<div class="post-metadata">

**Author:** ![ahuertas](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ahuertas/32/7487_2.png) [@ahuertas](https://forum.opennebula.io/u/ahuertas)\
**Post date:** [July 2, 2019, 10:00am UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/2 "2019-07-02T10:00:34Z")

</div>

Hello @saint

To use VNC with SSL, you need to add the following:

```auto
:vnc_proxy_support_wss: only
:vnc_proxy_cert: /etc/one/ssl/opennebula-certchain.pem
:vnc_proxy_key: /etc/one/ssl/opennebula-key.pem

```

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 2, 2019, 3:00pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/3 "2019-07-02T15:00:58Z")

</div>

Greetings Alejandro,  
I tried this without success (restarting sunstone and nginx)… Any other idea by any chance ?

---

<div class="post-metadata">

**Author:** ![ahuertas](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ahuertas/32/7487_2.png) [@ahuertas](https://forum.opennebula.io/u/ahuertas)\
**Post date:** [July 2, 2019, 3:01pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/4 "2019-07-02T15:01:34Z")

</div>

What error do you get?

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 2, 2019, 5:10pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/5 "2019-07-02T17:10:14Z")

</div>

When I try to launch the VNC,

VNC Server disconnected (code: 1006)

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 2, 2019, 5:27pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/6 "2019-07-02T17:27:58Z")

</div>

Here is the new config I tried:

```
#### OpenNebula Sunstone Upstream
upstream sunstone {
		server 127.0.0.1:9869;
		}
		
upstream websocketproxy {
    server 127.0.0.1:29876;
}

#### my.machine.com HTTPS host
server {
        listen 443 ssl;
        server_name machine.com;

        ### SSL Parameters
        #ssl on;
        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        ### Proxy requests to upstream
        location / {
                 proxy_pass http://sunstone;
                 proxy_redirect off;
                 proxy_set_header X-Real-IP $remote_addr;
	             proxy_set_header Host $http_host;
				 proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;
        }
        
        
        location /websockify {
        proxy_pass http://websocketproxy;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        add_header Access-Control-Allow-Origin *;
    }
}

```

And in the sunstone-server:  
:vnc\_proxy\_port: 29876  
:vnc\_proxy\_support\_wss: only  
:vnc\_proxy\_cert: /etc/ssl/certs/nginx-selfsigned.crt  
:vnc\_proxy\_key: /etc/ssl/private/nginx-selfsigned.key  
:vnc\_proxy\_ipv6: false  
:vnc\_request\_password: false

I made sure the .crt, .key, and .pem belong to oneadmin:oneadmin  
I restarted opennebula-sunstone, opennebubla-novnc, and Nginx

Still without success. Same error message as above.

---

<div class="post-metadata">

**Author:** ![ahuertas](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ahuertas/32/7487_2.png) [@ahuertas](https://forum.opennebula.io/u/ahuertas)\
**Post date:** [July 3, 2019, 6:59am UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/7 "2019-07-03T06:59:54Z")

</div>

What error do you see in `/var/log/one/novnc.log`?

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [July 3, 2019, 7:16am UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/8 "2019-07-03T07:16:50Z")

</div>

Hi,

You have configured ssl only for the websockets so you should try

```auto
proxy_pass https://websocketproxy;

```

If I am not wrong it will work in a slightly weird way - it will show 1006 but if you click to open in separate window it will work. The final solution I came to is as follow - in nginx I am using ssl cert from letsencrypt and a self-signed certificate for the websocketsproxy. There is a separate port on nginx for websocketproxy 89:

```auto
    # OpenNebula Sunstone upstream
    upstream sunstone {
        server 127.0.0.1:9869;
    }
    upstream websocketproxy {
        server 127.0.0.1:29876;
    }
    # No squealing.
    server_tokens off;
    # To upload ISO files, increase for VMs images
    client_max_body_size 4G;
    server {
        server_name public.host.com; # managed by Certbot
        root /usr/share/nginx/html;
        location / {
            proxy_pass http://sunstone;
            proxy_redirect off;
            log_not_found off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-FOR $proxy_add_x_forwarded_for;
        }
        location /websockify {
            proxy_http_version 1.1;
            proxy_pass http://websocketproxy;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            # VNC connection timeout
            proxy_read_timeout 61s;
            # Disable cache
            proxy_buffering off;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/public.host.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/public.host.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

    server {
        listen 89 ssl;
        listen [::]:89 ssl;
        server_name public.host.com;
        root /usr/share/nginx/html;
        location / {
            proxy_http_version 1.1;
            proxy_pass https://websocketproxy;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            # VNC connection timeout
            proxy_read_timeout 61s;
            # Disable cache
            proxy_buffering off;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        ssl_certificate /etc/letsencrypt/live/public.host.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/public.host.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }

```

The sunstone-server.conf is as follow:

```auto
:vnc_proxy_port: 127.0.0.1:29876
:vnc_proxy_support_wss: yes
:vnc_proxy_cert: /etc/pki/tls/certs/websockify.crt
:vnc_proxy_key: /etc/pki/tls/certs/websockify.key
:vnc_proxy_ipv6: false
:vnc_client_port: 89
:vnc_request_password: false

```

Not perfect but works for me …

Hope this helps 🙂

edit: just noticed that there are some configuration artifacts for websocket without ssl…

Best Regards,  
Anton Todorov

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 3, 2019, 1:00pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/9 "2019-07-03T13:00:13Z")

</div>

Hey Anton,

I tried what you recommended, and still not working.  
I will share my new configuration in a little while.  
Thank you for the help!

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 8, 2019, 6:55pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/10 "2019-07-08T18:55:18Z")

</div>

In the novice.log, all I have now is

`handler exception: [Errno 13] Permission denied`

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 9, 2019, 3:12pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/11 "2019-07-09T15:12:19Z")

</div>

I changed that with changing the rights to the private cert, but still get the VNC Diconnected: code 1006 now

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [July 10, 2019, 11:52am UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/12 "2019-07-10T11:52:22Z")

</div>

You should try oeningn the dev console in the browser and look the logged errors. Usualy there are hints from the browser what is not working (connection refused, cert not valid, etc…)

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 10, 2019, 1:44pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/13 "2019-07-10T13:44:16Z")

</div>

Would you have a link ?  
Because beside my basic dev console I did not find anything I could add-on regarding nginx…

---

<div class="post-metadata">

**Author:** ![saint](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@saint](https://forum.opennebula.io/u/saint)\
**Post date:** [July 11, 2019, 7:26pm UTC](https://forum.opennebula.io/t/how-to-use-ssl-with-ngnix/7403/14 "2019-07-11T19:26:25Z")

</div>

Issue resolved by redesigning part of our network.  
I wish we did not have to, but could not wait for this to be fixed.  
thanks
