I just spent a while getting octoprint to work using Nginx Proxy Manager docker image 1.26.0 and wanted to share my findings. I am using a wildcard certificate from the SecureTrust CA on nginx to plain-text HTTP on the octoprint side.
I was getting the dreaded websocket errors. I finally figured out that if I used "$scheme" for the X-Scheme header, the scheme would not be set properly. Hard coding this to "https" instead fixed that problem. I was also having a problem where occasionally, the webserver would redirect to the hostname with a comma and the hostname again. (e.g. octoprint.example.com,octoprint.example.com) This caused total failure. Sometimes, it would only happen in Safari, and other times, only in Chrome.
I finally got it figured out, and was able to setup both of my Octoprint instances behind nginx using Nginx Proxy Manager docker image 1.26.0 without any further issues. Here is what I recommend for using Nginx Proxy Manager on docker:
- Add a new proxy host
- Enter in the IP address and port of your Octoprint instance
- Enable "Websockets Support" (This adds the http_version, upgrade, and connection headers)
- Add a custom location for "/" using the same IP address and port of your octoprint instance
- Click the gear to enable the custom config text box
- Enter in the following:
proxy_set_header X-Scheme https;
client_max_body_size 0;
- Select the SSL tab and configure SSL
- Click save
That should do it. Using "https" as the scheme was the lynchpin for getting the websockets to work, and removing the "Host" header from the custom location fixed the redirect with the extra comma. If you are not using SSL in nginx, then you should omit the "X-Scheme" configuration line.
Many of the options that are recommended are automatically added to the config by Nginx Proxy Manager, and for whatever reason, adding them again causes issues.
You can also view the full configuration file that is created by looking where docker stores the files for the container that Nginx Proxy Manager is running in. Here is the proxy host config file for my working setup:
server {
set $forward_scheme http;
set $server "192.168.2.92";
set $port 80;
listen 8080;
listen [::]:8080;
listen 4443 ssl http2;
listen [::]:4443 ssl http2;
server_name octoprint.example.com;
# Custom SSL
ssl_certificate /data/custom_ssl/npm-1/fullchain.pem;
ssl_certificate_key /data/custom_ssl/npm-1/privkey.pem;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
access_log /data/logs/proxy-host-5_access.log proxy;
error_log /data/logs/proxy-host-5_error.log warn;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://192.168.2.92:80;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme https;
client_max_body_size 0;
}
# Custom
include /data/nginx/custom/server_proxy[.]conf;
}
Screenshots from Nginx Proxy Manager available at: https://imgur.com/a/SOKWdNx
I hope that helps someone.