My setup has 3 machines of relevance:
- Machine A hosts software known as BlueIris. This software records network enabled camera streams to disk, provides interfaces to review this footage, and can push alerts to iOS apps. This machine is not routable to the internet
- Machine B is a Raspberry Pi 3 running OpenHAB 1.X. This machine is also not routable to the internet.
- Machine C is a Raspberry Pi 3 with nginx acting as a proxy. It has an SSL certificate from LetsEncrypt. It is routable to the internet, having dual homes.
Configuring BlueIris or OpenHAB is not covered in this article. Nor is installing/compiling nginx. These tasks are documented elsewhere.
I strongly recommend you configure OpenHAB to have user authentication if you are opening this directly to the internet, as I show below.
Below is the configuration that works for me. It essentially does the following:
- Store 0 in $switch (the default behavior desired)
- If the user agent contains the case insensitive string "OpenHAB", store 1 in $switch
- If $switch is 0, route the request to Machine A
- If $switch is 1, route the request to Machine B
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream BlueIris {
server 10.0.0.5:80;
keepalive 5;
}
upstream OpenHAB {
server 10.0.0.4:8080;
keepalive 5;
}
server {
listen 80;
server_name localhost subdomain.domain.tld;
location / {
set $switch 0;
if ($http_user_agent ~* OpenHAB) {
set $switch 1;
}
proxy_bind 10.0.0.100;
if ($switch = 0) {
proxy_pass http://BlueIris;
}
if ($switch = 1 ) {
proxy_pass http://OpenHAB;
}
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxxxxx/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxxxxx/privkey.pem; # managed by Certbot
ssl_session_cache shared:le_nginx_SSL:1m; # managed by Certbot
ssl_session_timeout 1440m; # managed by Certbot
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # managed by Certbot
ssl_prefer_server_ciphers on; # managed by Certbot
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-ECDSA-AES256-GCM-SHA384 ECDHE-ECDSA-AES128-SHA ECDHE-ECDSA-AES256-SHA ECDHE-ECDSA-AES128-SHA256 ECDHE-ECDSA-AES256-SHA384 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-RSA-AES256-GCM-SHA384 ECDHE-RSA-AES128-SHA ECDHE-RSA-AES128-SHA256 ECDHE-RSA-AES256-SHA384 DHE-RSA-AES128-GCM-SHA256 DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES128-SHA DHE-RSA-AES256-SHA DHE-RSA-AES128-SHA256 DHE-RSA-AES256-SHA256 EDH-RSA-DES-CBC3-SHA"; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
}
No comments:
Post a Comment