NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
22.59k stars 2.62k forks source link

workaround for prompting the 'Bad Gateway' when you login after reboot the NPM container #1772

Open sshuangliu opened 2 years ago

sshuangliu commented 2 years ago

my env:

pi 3 B+

my configuration:

version: '3' services: app: image: 'jc21/nginx-proxy-manager:latest' restart: unless-stopped ports:

the screenshot:

image

workaround

stop the container-------start the container-----login---------input: username: admin@example.com pwd: changeme (you need type the pwd again rathen then autofill by browser)-------prompt 'No relevant user found'------------use the normal credential to login----all works again!!!!

it doesn't work if you restart the container

image

the bug and the workaround can reappear, I have no idea about how to check what version the installed NPM is

sorry for my poor english hope this would be useful for you

one more thing: I use 'portainer' to manage my container and deploy docker-compose

image

thanks sam

abhishekmj303 commented 2 years ago

I'm also having this problem but the workaround did not work for me. I also use portainer. When I stopped the container and started the container again, it again showed "Bad Gateway".

OS: Ubuntu 20.04 NPM Version: 2.9.15

Here are my logs of docker container when I stopped and started:

s6-svscanctl: fatal: unable to control /var/run/s6/services: supervisor not listening
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[1/28/2022] [1:51:44 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01_perms.sh: executing... 
Changing ownership of /data/logs to 0:0
[cont-init.d] 01_perms.sh: exited 0.
[cont-init.d] 01_s6-secret-init.sh: executing... 
[cont-init.d] 01_s6-secret-init.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
❯ Enabling IPV6 in hosts: /etc/nginx/conf.d
  ❯ /etc/nginx/conf.d/production.conf
  ❯ /etc/nginx/conf.d/include/proxy.conf
  ❯ /etc/nginx/conf.d/include/block-exploits.conf
  ❯ /etc/nginx/conf.d/include/ip_ranges.conf
  ❯ /etc/nginx/conf.d/include/ssl-ciphers.conf
  ❯ /etc/nginx/conf.d/include/assets.conf
  ❯ /etc/nginx/conf.d/include/force-ssl.conf
  ❯ /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf
  ❯ /etc/nginx/conf.d/include/resolvers.conf
  ❯ /etc/nginx/conf.d/default.conf
❯ Enabling IPV6 in hosts: /data/nginx
[1/28/2022] [1:51:55 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)
[1/28/2022] [1:51:56 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)
[1/28/2022] [1:51:57 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)
[1/28/2022] [1:51:58 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)
[1/28/2022] [1:51:59 PM] [Global   ] › ✖  error     ER_ACCESS_DENIED_ERROR: Access denied for user 'npm'@'172.22.0.2' (using password: YES)

This is my docker-compose file:

version: '3'
services:
        app:
                image: 'jc21/nginx-proxy-manager:latest'
                ports:
                        - '80:80'
                        - '81:81'
                        - '443:443'
                environment:
                        DB_MYSQL_HOST: "db"
                        DB_MYSQL_PORT: 3306
                        DB_MYSQL_USER: "npm"
                        DB_MYSQL_PASSWORD: "npm"
                        DB_MYSQL_NAME: "npm"
                volumes:
                        - ./data:/data
                        - ./letsencrypt:/etc/letsencrypt

        db:
                image: 'jc21/mariadb-aria:latest'
                environment:
                        MYSQL_ROOT_PASSWORD: 'npm'
                        MSQL_DATABASE: 'npm'
                        MYSQL_USER: 'npm'
                        MYSQL_PASSWORD: 'npm'
                volumes:
                        - ./data/mysql:/var/lib/mysql
kt-solutions commented 2 years ago

For me it worked to have this db-image instead of the latest:

jc21/mariadb-aria:10.4.15-innodb

bencollinz commented 2 years ago

This didn't work for me either. Updating didn't work either. I'm stuck. It's running but I can't log in. What changed?

abhishekmj303 commented 2 years ago

@bencollinz this script worked for me : https://github.com/bmcgonag/docker_installs Also try rebooting the system before running the script.

bencollinz commented 2 years ago

@bencollinz this script worked for me : https://github.com/bmcgonag/docker_installs Also try rebooting the system before running the script.

That didn't change anything, still get the bad gateway at login and this in logs:

[3/30/2022] [1:56:25 PM] [Global ] › ✖ error connect EHOSTUNREACH 172.19.0.2:3306 [3/30/2022] [1:56:26 PM] [Global ] › ✖ error getaddrinfo EAI_AGAIN db [3/30/2022] [1:56:27 PM] [Global ] › ✖ error getaddrinfo EAI_AGAIN db [3/30/2022] [1:56:28 PM] [Global ] › ✖ error getaddrinfo EAI_AGAIN db [3/30/2022] [1:56:29 PM] [Global ] › ✖ error getaddrinfo EAI_AGAIN db

lockheed commented 2 years ago

I have the same problem since 2 or 3 months now, so I was unable to do any configuration change to NPM. Why is the no developer input on this fatal bug?

ajcoll5 commented 2 years ago

@abhishekmj303 You've got a miss-spelling in your db environment variables - should be MYSQL_DATABASE not MSQL_DATABASE.

You might also be missing the config.json file. Under volumes, add the following:

- ./config.json:/app/config/production.json

Make sure you create a blank config.json file in your folder BEFORE starting the container - otherwise Docker will assume you want a folder and creates a folder.

lockheed commented 2 years ago

The issue is caused by NPM not being able to connect to mysql DB anymore because the mysql rejects it connections. Once it happens, there is no known fix for this. Switching to SQLite solved the problem for me. Contrary to the popular belief, SQLite seems to be a more performant option anyway.

abhishekmj303 commented 2 years ago

@abhishekmj303 You've got a miss-spelling in your db environment variables - should be MYSQL_DATABASE not MSQL_DATABASE.

@ajcoll5 Oh, yeah. This might be the issue I had. Thank You. You might also be missing the config.json file. Under volumes, add the following:

- ./config.json:/app/config/production.json

Make sure you create a blank config.json file in your folder BEFORE starting the container - otherwise Docker will assume you want a folder and creates a folder.

But I think this is not necessary. I'm able to run without this line.

truthsword commented 2 years ago

I have this today. Runing npm on RPi container using Portainer Stack. All was good 6 weeks ago. Here is docker-compose:

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '4443:4443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "nm"
      DB_MYSQL_PASSWORD: "nm"
      DB_MYSQL_NAME: "nm"
      # Uncomment this if IPv6 is not enabled on your host
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: 'yobasystems/alpine-mariadb:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 'nm'
      MYSQL_DATABASE: 'nm'
      MYSQL_USER: 'nm'
      MYSQL_PASSWORD: 'nm'
    volumes:
      - ./data/mysql:/var/lib/mysql

Updated containers, stopped/started the stack, rebooted the RPI... all no joy.

Using for RP and LE wildcard cert updates. Everything is running, but I cannot enter.

I saw a procedure for "forgotten" password... has anyone tried that?

ajcoll5 commented 2 years ago

@truthsword Anything in your logs or in the browser console?

truthsword commented 2 years ago

@truthsword Anything in your logs or in the browser console?

Nothing helpful. I stopped the stack and renamed the data and mariadb folders (under npm), restarted and was able to set up a new users. So it seems the compose and image files are fine.

I then tried to use the original mariadb folder, with a new data folder... and still had the Bad Gateway error. It seems (as mentioned above) that the mariadb container is rejecting npm logins.

luisced commented 2 years ago

Evening, I had the same issue as you guys. This reddit post saved my life, I hope it can help you 👍

https://www.reddit.com/r/nginx/comments/pt352s/bad_gateway_on_login/hdvucab/

nicabreon commented 2 years ago

I had same issue too, in my case it because db sqlite file permission changed, so I change file permission and restart container. Then all return normal

ghost commented 2 years ago

try, login mariadb select user,host,plugin,password from user where user = ‘npm’; see host <% or localhost>

modify host -> % or npm service ip: update user set host=‘172.18.0.3’ where user = ‘npm’; or update user set host=‘%’ where user = ‘npm’; again

grant all on npm.* to 'npm’@‘%’; :)

ali80 commented 1 year ago

take a look at its logs, mine had network error and got stuck in renewing the certificates

marcosvfc commented 1 year ago

After some time, making a lot of changes, for me the problem was my password in docker-compose file. Some characters or the length of the password, can be a problem.

DonBamboo commented 1 year ago

Whew! after so many hours of figuring out what the problem is my solution is use the npm version 2.9.18 if you use latest then it will return error I'm not sure why?

version: "3.8"

services: mariadb: container_name: MariaDB image: "jc21/mariadb-aria:latest" restart: always healthcheck: test: mysqladmin ping -h mariadb --password=${MYSQL_ROOT_PASSWORD} interval: 1s retries: 15 environment:

networks: nginx_network: external: true

ChiefMedicalOfficer commented 1 year ago

Whew! after so many hours of figuring out what the problem is my solution is use the npm version 2.9.18 if you use latest then it will return error I'm not sure why?

version: "3.8"

services: mariadb: container_name: MariaDB image: "jc21/mariadb-aria:latest" restart: always healthcheck: test: mysqladmin ping -h mariadb --password=${MYSQL_ROOT_PASSWORD} interval: 1s retries: 15 environment:

  • MYSQL_ROOT_PASSWORD
  • MYSQL_DATABASE
  • MYSQL_USER
  • MYSQL_PASSWORD volumes:
  • ./data/mysql:/var/lib/mysql networks:
  • nginx_network

    nginx: container_name: Nginx-Proxy-Manager image: jc21/nginx-proxy-manager:2.9.18 restart: always ports:

  • "80:80"
  • "81:81"
  • "443:443" environment:
  • DB_MYSQL_HOST
  • DB_MYSQL_PORT
  • DB_MYSQL_USER
  • DB_MYSQL_PASSWORD
  • DB_MYSQL_NAME volumes:
  • ./data:/data
  • ./letsencrypt:/etc/letsencrypt

    - ./config.json:/app/config/production.json

    networks:

  • nginx_network

networks: nginx_network: external: true

Thank you so much. Such a simple fix for a really annoying problem.

SortedPixel commented 1 year ago

Latest solution:

The problem is that you cannot "nest" the mysql folder inside the npm data folder. So in your linked docker container file may have:

- volumes: - ./data:/data under the npm app

and

- volumes: - ./data/mysql:/var/lib/mysql under the db app

Just change take the /mysql folder out of data and it will work Example change volumes line under db to

volumes: - ./mysql:/var/lib/mysql

Thanks.

MotazHakim commented 1 year ago

Latest solution:

The problem is that you cannot "nest" the mysql folder inside the npm data folder. So in your linked docker container file may have:

- volumes: - ./data:/data under the npm app

and

- volumes: - ./data/mysql:/var/lib/mysql under the db app

Just change take the /mysql folder out of data and it will work Example change volumes line under db to

volumes: - ./mysql:/var/lib/mysql

Thanks.

Worked for me , was just going to write this solution

GitKli22 commented 11 months ago

I also have this issue, but the workaround didn't work for me. I'm also using Portainer. When I stopped and restarted the container, it showed "Bad Gateway" again.

However, I resolved it by focusing on the database jc21/mariadb-aria:10.4.15-innodb. Since it's showing "Bad Gateway," it means there's a lack of a service; in my case, it's the database. So, I stopped and restarted the database, and it worked

github-actions[bot] commented 3 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1: