Skip to content

Instantly share code, notes, and snippets.

@shbatm
Created December 16, 2018 21:20
Show Gist options
  • Save shbatm/f8f335a64ef5c364e6a62131e173e2a9 to your computer and use it in GitHub Desktop.
Save shbatm/f8f335a64ef5c364e6a62131e173e2a9 to your computer and use it in GitHub Desktop.
Running diyHue on a non-default HTTP and HTTPS port

How to use non-default Ports for diyHue Project using NGINX

This GIST contains the files required to be modified in order to run diyHue on non-default HTTP and HTTPS ports.

This example uses ports 8080 for HTTP and 8443 for HTTPS and redirects the necessary paths from NGINX's default site.

Changes made to diyHue Files

The following lines must be changed in the diyHue source code, as there is no option provided to change the ports by default.

If installed in the default location, modify the following lines in /opt/hue-emulator/HueEmulator3.py:

# Change line 1679 from:
        server_address = ('', 443)
# To:
        server_address = ('', 8443)
        
# Change line 1692 from:
        server_address = ('', 80)
# To:
        server_address = ('', 8080)
# /etc/nginx/conf.d/acme.inc
# Allow access to the ACME Challenge for Let's Encrypt
location ^~ /.well-known/acme-challenge {
allow all;
alias /var/www/acme;
}
# Relevent Portions of NGINX /etc/nginx/sites-enabled/default
# Designed to host diyHue on HTTP-8080 and HTTPS-8443
server {
listen 80 default_server;
# listen [::]:80 default_server;
server_name yourservername;
include conf.d/acme.inc; # Let's Encrypt Details
location /api/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass http://127.0.0.1:8080;
}
location /hue/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass http://127.0.0.1:8080;
}
location /tradfi/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass http://127.0.0.1:8080;
}
location /deconz/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass http://127.0.0.1:8080;
}
location = /description.xml {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass http://127.0.0.1:8080;
}
include conf.d/redirect_http.inc;
}
server {
# SSL configuration
#
listen 127.0.0.1:443 ssl default_server;
#listen [::]:8443 ssl default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name yourservername;
location ^~ /api/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass https://127.0.0.1:8443;
}
location ^~ /hue/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass https://127.0.0.1:8443;
}
location ^~ /tradfi/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass https://127.0.0.1:8443;
}
location ^~ /deconz/ {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass https://127.0.0.1:8443;
}
location = /description.xml {
include conf.d/proxy_set_header.inc;
allow all;
proxy_pass https://127.0.0.1:8443;
}
# /etc/nginx/conf.d/proxy_set_header.inc
proxy_set_header X-Forwarded-By $server_addr:$server_port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# /etc/nginx/conf.d/redirect_http.inc
location / {
return 301 https://$host$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment