Nginx Proxy Manager is a great tool for organizing your services. However, there are some tricks to use on Raspberry Pi.
Nginx Proxy Manager sometimes gives "Bad Gateway" when it's not ready. Please wait a minute before searching for other possible causes.
The way leads to the "Bad Gateway" error #
This section is not the solution. DO NOT follow this section blindly! READ ON!
Nginx Proxy Manager will try to install the Certbot DNS challenge package (certbot-dns-<provider>
) after you have configured SSL using DNS challenges. But the installation didn't succeed and reported some compilation errors.
I managed to install the packages by running:
docker exec -it nginxpm_app_1 bash
And install many build dependencies (according to https://github.com/NginxProxyManager/nginx-proxy-manager/issues/2070 ):
apt-get install -y build-essential libssl-dev libffi-dev python3-dev cargo
Not so important here, but if it gives you the “No Installation Candidate” error, you can try referring to the source list here.
However, even though I successfully installed the package, I couldn't find the certificate to use for the domain. So I shutdown the compose and restarted it, without realizing the installed build dependencies are cleared. When I navigate to the admin board and try to log in, it keeps giving me the "Bad Gateway" error.
Solving the problem #
The "Bad Gateway" error typically means that the service is not available. And the Nginx Proxy Manager is not available since it keeps trying to install the certbot-dns-*
package and failed.
The tricky part is that the error logs are not printed immediately, but after the attempt to install the certbot-dns-*
package has failed. So it's not obvious at the first sight that there is some error installing the package. (I didn't realize that the packages installed in the above section had been wiped out because of the shutdown.)
Since the install-build-dependencies approach is cumbersome and not persistent, is there anything else we can do? Things will be much better if the packages are pre-compiled. Fortunately, yes! piwheels is a Python package repository providing Arm platform wheels (pre-compiled binary Python packages) specifically for the Raspberry Pi, making pip installations much faster. Thus installing from piwheels is the way to go!
The code #
The basic idea is to add piwheels to /etc/pip.conf
and install. So we can create a file called ./app/Dockerfile
:
FROM jc21/nginx-proxy-manager:latest
RUN echo -e "[global]\nextra-index-url=https://www.piwheels.org/simple" > /etc/pip.conf
RUN pip install certbot-dns-<your provider> --no-cache-dir
ENTRYPOINT [ "/init" ]
And change docker-compose.yml
to:
# image: 'jc21/nginx-proxy-manager:latest'
build: ./app
I've proposed adding the index to the original image at https://github.com/NginxProxyManager/nginx-proxy-manager/issues/2161
Still slow piwheels? #
piwheels is ridiculously slow in my country, so it would be better if I could use a proxy for piwheels. And it's possible using build args:
build:
context: ./app
args:
https_proxy: 'http://192.168.111.222:9876'
http_proxy: 'http://192.168.111.222:9876'
Hi, After getting bad gateway on a new nginx proxy manager docker install...i tried your guide
On a raspberry pi 4
Think i'm close to getting it working - followed guide from https://allanchain.github.io/blog/post/nginx-proxy-manager-502/