Skip to content

Instantly share code, notes, and snippets.

@mfalkvidd
Last active February 7, 2024 17:02
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mfalkvidd/3920bd5035806a583b5c1e20eaddabae to your computer and use it in GitHub Desktop.
Save mfalkvidd/3920bd5035806a583b5c1e20eaddabae to your computer and use it in GitHub Desktop.
Thingsboard nginx reverse proxy with websocket and HTTPS support (Let's Encrypt)
server {
listen 80;
server_name EXTERNAL_THINGSBOARD_DOMAIN.com;
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
listen 443 ssl;
server_name EXTERNAL_THINGSBOARD_DOMAIN.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 1d;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
location / {
proxy_pass http://LOCAL_THINGSGBOARD_IP_OR_DOMAN:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}
@XudongLiu
Copy link

This doc is very helpful. Thx.

@goboras
Copy link

goboras commented Apr 27, 2018

Works out of the box. Thanks

@motechsolutions
Copy link

motechsolutions commented Jun 28, 2018

Worked a treat for me, thank you

@BasSwildens
Copy link

BasSwildens commented Jul 10, 2018

location /dashboard/ {
proxy_pass http://LOCAL_THINGSGBOARD_IP_OR_DOMAN:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

Thanks for your work on this, it was very helpfull. It looks like if I use a sub path like https://THINGBOARD.DOMAIN/dashboard/ there is a problem with serving javacomponents to the browser resulting in a blank page. Any thoughts on this?

Is there a config entry available to tune the root url in thingsboard?

root_url = %(protocol)s://%(domain)s/dashboard/

@paolofrs
Copy link

worked for me alse (docker compose with nginx and thingsboard). Thank you very much!

@rsurgiewicz
Copy link

location /dashboard/ {
proxy_pass http://LOCAL_THINGSGBOARD_IP_OR_DOMAN:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

Thanks for your work on this, it was very helpfull. It looks like if I use a sub path like https://THINGBOARD.DOMAIN/dashboard/ there is a problem with serving javacomponents to the browser resulting in a blank page. Any thoughts on this?

Is there a config entry available to tune the root url in thingsboard?

root_url = %(protocol)s://%(domain)s/dashboard/

Hi, same problem
tried nginx with location
/thingsboard but JS content is not loading.
@BasSwildens Did You find a solution?

@BasSwildens
Copy link

location /dashboard/ {
proxy_pass http://LOCAL_THINGSGBOARD_IP_OR_DOMAN:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

Thanks for your work on this, it was very helpfull. It looks like if I use a sub path like https://THINGBOARD.DOMAIN/dashboard/ there is a problem with serving javacomponents to the browser resulting in a blank page. Any thoughts on this?
Is there a config entry available to tune the root url in thingsboard?

root_url = %(protocol)s://%(domain)s/dashboard/

Hi, same problem
tried nginx with location
/thingsboard but JS content is not loading.
@BasSwildens Did You find a solution?

We used a workaround by adding an extra CNAME to our dns, https://dashboard.domainname.com

@rsurgiewicz
Copy link

thanks, I might also try with rewrite plugin

@DavidR-fr
Copy link

Thanks it works out of the box for me as well !!

@medking82
Copy link

medking82 commented Sep 7, 2020

it works
but in my server, my nginx (1.14 ) conf is this path "/etc/nginx/sites-available/deafult"

i modify "default" by this method, it works well, thank you very much

@michalfapso
Copy link

Thanks, @mfalkvidd! I used your config for a dockerized version of Thingsboard + Nginx reverse proxy here: https://github.com/michalfapso/thingsboard_docker_https

@ferchinas
Copy link

Hi: Thank you very much for sharing the configuration.
Communication with a Flutter App. The http, https and ws requests work fine, but when I try to wss, flutter gives me the following error: WRONG_VERSION_NUMBER (tls_record.cc:242)
Does anyone know how to fix it?

@navneet-indusworks
Copy link

Thank You so much for this... I was trying to solve this for 3 hours

@wz2b
Copy link

wz2b commented Feb 7, 2024

This is very helpful. One thing I want to raise here is that there are issues with http2 and thingsboard with certain browsers like Chrome. One way to get around this is to do use an nginx proxy, which can't relay to the backend using http2 anyway. I think that there might be some advantage to enable http2 anyway:

listen 1.2.3.4:443 ssl http2;

so that the client can talk to nginx using http2, then nginx will talk to thingsboard using http/1.1 which should get around the problem of thingsboard running out of connections.

Either way ... keep http/2 in mind when you do this and make a deliberate decision what to do; the way you have this written it may be disabled (which may be exactly what you want).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment