Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad Gateway at Admin Page: production.json cannot be read #333

Closed
bookandrelease opened this issue Mar 20, 2020 · 42 comments
Closed

Bad Gateway at Admin Page: production.json cannot be read #333

bookandrelease opened this issue Mar 20, 2020 · 42 comments

Comments

@bookandrelease
Copy link

bookandrelease commented Mar 20, 2020

I have been trying for days to get this to function with SSL. After a couple days it finally worked, but I eventually got "internal error" when trying to obtain an SSL for one of the proxies. I then tried to reinstall, but now I get "Bad Gateway" when trying to login to the admin portal.

Portainer shows the desktop_app_1 container is unhealthy and shows an error of "parse error: Invalid numeric literal at line 1, column 7 NOT OK".

Docker version 19.03.8, build afacb8b7f0
Ubuntu LTS 18.04
docker-compose version 1.25.4, build 8d51620a

Please help. I have a domain I paid for that also has an SSL through dnsimple.

docker-compose.yaml
version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./config.json:/app/config/production.json
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
  db:
    image: 'jc21/mariadb-aria:10.4'
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql
desktop_db1_ output
[i] mysqld not found, creating....,
[i] MySQL data directory not found, creating initial DBs,
 Creating database: npm,
[i] with character set: 'utf8' and collation: 'utf8_general_ci',
[i] Creating user: npm with password npm,
2020-03-20  7:27:32 0 [Note] /usr/bin/mysqld (mysqld 10.4.10-MariaDB) starting as process 70 ...,
2020-03-20  7:27:32 0 [Note] InnoDB: Using Linux native AIO,
2020-03-20  7:27:32 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins,
2020-03-20  7:27:32 0 [Note] InnoDB: Uses event mutexes,
2020-03-20  7:27:32 0 [Note] InnoDB: Compressed tables use zlib 1.2.11,
2020-03-20  7:27:32 0 [Note] InnoDB: Number of pools: 1,
2020-03-20  7:27:32 0 [Note] InnoDB: Using SSE2 crc32 instructions,
2020-03-20  7:27:32 0 [Note] mysqld: O_TMPFILE is not supported on /var/tmp (disabling future attempts),
2020-03-20  7:27:32 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M,
2020-03-20  7:27:32 0 [Note] InnoDB: Completed initialization of buffer pool,
2020-03-20  7:27:32 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().,
2020-03-20  7:27:32 0 [Note] InnoDB: 128 out of 128 rollback segments are active.,
2020-03-20  7:27:32 0 [Note] InnoDB: Creating shared tablespace for temporary tables,
2020-03-20  7:27:32 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...,
2020-03-20  7:27:32 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.,
2020-03-20  7:27:32 0 [Note] InnoDB: 10.4.10 started; log sequence number 139836; transaction id 21,
2020-03-20  7:27:32 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool,
2020-03-20  7:27:32 0 [Note] Plugin 'FEEDBACK' is disabled.,
2020-03-20  7:27:32 0 [Note] InnoDB: Buffer pool(s) load completed at 200320  7:27:32,
2020-03-20  7:27:32 6 [Warning] 'user' entry '@21b64543b884' ignored in --skip-name-resolve mode.,
2020-03-20  7:27:32 6 [Warning] 'proxies_priv' entry '@% root@21b64543b884' ignored in --skip-name-resolve mode.,
2020-03-20  7:27:32 6 [Warning] 'user' entry '@21b64543b884' ignored in --skip-name-resolve mode.,
2020-03-20  7:27:32 6 [Warning] 'proxies_priv' entry '@% root@21b64543b884' ignored in --skip-name-resolve mode.,
/scripts/run.sh: ignoring or entrypoint initdb empty /docker-entrypoint-initdb.d/*,
,
,
MySQL init process done. Ready for start up.,
,
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0,
2020-03-20  7:27:34 0 [Note] /usr/bin/mysqld (mysqld 10.4.10-MariaDB) starting as process 1 ...,
2020-03-20  7:27:34 0 [Note] InnoDB: Using Linux native AIO,
2020-03-20  7:27:34 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins,
2020-03-20  7:27:34 0 [Note] InnoDB: Uses event mutexes,
2020-03-20  7:27:34 0 [Note] InnoDB: Compressed tables use zlib 1.2.11,
2020-03-20  7:27:34 0 [Note] InnoDB: Number of pools: 1,
2020-03-20  7:27:34 0 [Note] InnoDB: Using SSE2 crc32 instructions,
2020-03-20  7:27:34 0 [Note] mysqld: O_TMPFILE is not supported on /var/tmp (disabling future attempts),
2020-03-20  7:27:34 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M,
2020-03-20  7:27:34 0 [Note] InnoDB: Completed initialization of buffer pool,
2020-03-20  7:27:34 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().,
2020-03-20  7:27:34 0 [Note] InnoDB: 128 out of 128 rollback segments are active.,
2020-03-20  7:27:34 0 [Note] InnoDB: Creating shared tablespace for temporary tables,
2020-03-20  7:27:34 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...,
2020-03-20  7:27:34 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.,
2020-03-20  7:27:34 0 [Note] InnoDB: 10.4.10 started; log sequence number 139845; transaction id 21,
2020-03-20  7:27:34 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool,
2020-03-20  7:27:34 0 [Note] Plugin 'FEEDBACK' is disabled.,
2020-03-20  7:27:34 0 [Note] InnoDB: Buffer pool(s) load completed at 200320  7:27:34,
2020-03-20  7:27:34 0 [Note] Server socket created on IP: '::'.,
2020-03-20  7:27:34 0 [Warning] 'user' entry '@21b64543b884' ignored in --skip-name-resolve mode.,
2020-03-20  7:27:34 0 [Warning] 'proxies_priv' entry '@% root@21b64543b884' ignored in --skip-name-resolve mode.,
2020-03-20  7:27:34 0 [Note] Reading of all Master_info entries succeeded,
2020-03-20  7:27:34 0 [Note] Added new Master_info '' to hash table,
2020-03-20  7:27:34 0 [Note] /usr/bin/mysqld: ready for connections.,
Version: '10.4.10-MariaDB'  socket: '/run/mysqld/mysqld.sock'  port: 3306  MariaDB Server,

desktop_app_1 output:

[3/20/2020] [7:28:38 AM] [Global   ] › ✖  error     Config file /app/config/production.json cannot be read. Error code is: EISDIR. Error message is: EISDIR: illegal operation on a directory, read Error: Config file /app/config/production.json cannot be read. Error code is: EISDIR. Error message is: EISDIR: illegal operation on a directory, read
    at Config.util.parseFile (/app/node_modules/config/lib/config.js:771:13)
    at /app/node_modules/config/lib/config.js:601:26
    at Array.forEach (<anonymous>)
    at Config.util.loadFileConfigs (/app/node_modules/config/lib/config.js:600:16)
    at new Config (/app/node_modules/config/lib/config.js:116:27)
    at Object.<anonymous> (/app/node_modules/config/lib/config.js:1441:31)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.j
@GuISm0
Copy link

GuISm0 commented Mar 21, 2020

Hi, I have the same problem on my RPI3 and I use the same docker-compose.yaml with nom in version 2.2.0.

@bookandrelease
Copy link
Author

In addition, my error log shows this multiple times:

2020/03/21 22:06:24 [error] 223#223: *82 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: nginxproxymanager, request: "GET /api/ HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "127.0.0.1:81"

@mspencerl87
Copy link

docker-compose up -d created a directory config.json/ instead of a file.
stop containers
sudo rm -r config.json directory
create config.json file with:
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}

@lopugit
Copy link

lopugit commented Mar 25, 2020

I'm getting this too :'(

On tag :2

@DonSYS91
Copy link

DonSYS91 commented Mar 25, 2020

You're getting "Bad Gateway" because the upstream server which is the node app listening on port 3000 is not running or error-ed out and died.

  1. go inside the docker docker exec -it 6b99f027ff4d sh where the hex string is the container ID taken from docker ps
  2. check if node is listening on port 3000: netstat -tulpn
  3. if not try to run it manually to see what error you get node --abort_on_uncaught_exception --max_old_space_size=250 index.js

But I'm pretty sure you just didn't create config.json which is stated so clearly in the docs, if you didn't do what @mspencerl87 and you're good to go

@bookandrelease
Copy link
Author

docker-compose up -d created a directory config.json/ instead of a file.
stop containers
sudo rm -r config.json directory
create config.json file with:
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}

Interesting. I’m not sure how I didn’t notice that if that was the case. I don’t know why, but I tried again yesterday and it all of a sudden decided to work. Both the login and ssl certs are working. I will leave the issue open for the other commenter who is having it.

@bookandrelease
Copy link
Author

You're getting "Bad Gateway" because the upstream server which is the node app listening on port 3000 is not running or error-ed out and died.

  1. go inside the docker docker exec -it 6b99f027ff4d sh where the hex string is the container ID taken from docker ps
  2. check if node is listening on port 3000: netstat -tulpn
  3. if not try to run it manually to see what error you get node --abort_on_uncaught_exception --max_old_space_size=250 index.js

But I'm pretty sure you just didn't create config.json which is stated so clearly in the docs, if you didn't do what @mspencerl87 and you're good to go

I don’t see anything about it in the Quick Setup. Which is what I used because I’m new to docker, self hosting, and all that.

@wwboynton
Copy link

Seconding @bookandrelease's sentiments here -- @donmccoy is right that the config.json is clearly outlined in the full setup, but it is notably absent from the quick setup which is also linked from the top of the repo's README.md. It's a pretty reasonable expectation that a quick setup guide would get the majority of users up-and-running without much fuss.

Additionally, it seems like there's a bug where instead of creating a default config.json file, the first run of the container is creating a config.json directory by mistake, which must first be deleted. I outlined that here.

@daledude
Copy link

You're getting "Bad Gateway" because the upstream server which is the node app listening on port 3000 is not running or error-ed out and died.

  1. go inside the docker docker exec -it 6b99f027ff4d sh where the hex string is the container ID taken from docker ps
  2. check if node is listening on port 3000: netstat -tulpn
[root@docker-1341f207466a:/app]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      192/nginx: master p
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      192/nginx: master p
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      192/nginx: master p
tcp        0      0 :::80                   :::*                    LISTEN      192/nginx: master p
tcp        0      0 :::81                   :::*                    LISTEN      192/nginx: master p
tcp        0      0 :::443                  :::*                    LISTEN      192/nginx: master p
  1. if not try to run it manually to see what error you get node --abort_on_uncaught_exception --max_old_space_size=250 index.js
[root@docker-1341f207466a:/app]# node --abort_on_uncaught_exception --max_old_space_size=250 index.js
[3/27/2020] [3:36:22 PM] [Global   ] › ✖  error     connect ETIMEDOUT
[3/27/2020] [3:36:33 PM] [Global   ] › ✖  error     connect ETIMEDOUT
[3/27/2020] [3:36:44 PM] [Global   ] › ✖  error     connect ETIMEDOUT
[3/27/2020] [3:36:55 PM] [Global   ] › ✖  error     connect ETIMEDOUT
[3/27/2020] [3:37:06 PM] [Global   ] › ✖  error     connect ETIMEDOUT

But I'm pretty sure you just didn't create config.json which is stated so clearly in the docs, if you didn't do what @mspencerl87 and you're good to go

I did read the docs for the Full Setup Instructions and still get Bad Gateway.

podman run --detach=true --log-driver=journald '--log-opt=tag={{.Name}}' --pull=always --volume=/opt/container/service-volumes/production/nginx_proxy_manager/config.json:/app/config/production.json:rw --volume=/opt/container/service-volumes/production/nginx_proxy_manager/data:/data:rw --volume=/opt/container/service-volumes/production/nginx_proxy_manager/letsencrypt:/etc/letsencrypt:rw --rm --net=private --no-hosts=true --name=nginx_proxy_manager jc21/nginx-proxy-manager:2
cat /opt/container/service-volumes/production/nginx_proxy_manager/config.json
{
  "database": {
    "engine": "mysql",
    "host": "server",
    "name": "nginx_proxy_manager",
    "user": "nginx_proxy_manager",
    "password": "password",
    "port": 3306
  }
}
ls -l /opt/container/service-volumes/production/nginx_proxy_manager/data/
total 0
drwxr-xr-x 2 root root 0 Mar 27 17:20 access
drwxr-xr-x 2 root root 0 Mar 27 17:20 custom_ssl
drwxr-xr-x 2 root root 0 Mar 27 17:20 letsencrypt-acme-challenge
drwxr-xr-x 2 root root 2 Mar 27 17:20 logs
drwxr-xr-x 9 root root 9 Mar 27 17:20 nginx
[root@docker-1341f207466a:/app]# ps auxf
PID   USER     TIME  COMMAND
    1 root      0:00 s6-svscan -t0 /var/run/s6/services
   33 root      0:00 s6-supervise s6-fdholderd
  188 root      0:00 s6-supervise nginx
  190 root      0:00 s6-supervise manager
  192 root      0:00 nginx: master process nginx
  194 root      0:00 bash ./run
  211 root      0:01 node --abort_on_uncaught_exception --max_old_space_size=250 index.js
  223 root      0:00 nginx: worker process
  224 root      0:00 nginx: worker process
  225 root      0:00 nginx: worker process
  226 root      0:00 nginx: worker process
  227 root      0:00 nginx: worker process
  228 root      0:00 nginx: worker process
  229 root      0:00 nginx: worker process
  230 root      0:00 nginx: worker process
  231 root      0:00 nginx: worker process
  232 root      0:00 nginx: worker process
  233 root      0:00 nginx: worker process
  234 root      0:00 nginx: worker process
  235 root      0:00 nginx: worker process
  236 root      0:00 nginx: worker process
  237 root      0:00 nginx: worker process
  238 root      0:00 nginx: worker process
  239 root      0:00 nginx: worker process
  240 root      0:00 nginx: worker process
  241 root      0:00 nginx: worker process
  242 root      0:00 nginx: worker process
  243 root      0:00 nginx: worker process
  244 root      0:00 nginx: worker process
  245 root      0:00 nginx: worker process
  246 root      0:00 nginx: worker process
  247 root      0:00 nginx: worker process
  248 root      0:00 nginx: worker process
  249 root      0:00 nginx: worker process
  250 root      0:00 nginx: worker process
  251 root      0:00 nginx: worker process
  252 root      0:00 nginx: worker process
  253 root      0:00 nginx: worker process
  254 root      0:00 nginx: worker process
  255 root      0:00 nginx: worker process
  256 root      0:00 nginx: worker process
  257 root      0:00 nginx: worker process
  258 root      0:00 nginx: worker process
  259 root      0:00 nginx: worker process
  260 root      0:00 nginx: worker process
  261 root      0:00 nginx: worker process
  262 root      0:00 nginx: worker process
  263 root      0:00 nginx: cache manager process
  271 root      0:00 /bin/bash
  299 root      0:00 ps auxf
2020/03/27 17:36:59 [error] 223#223: *2 connect() failed (111: Connection refused) while connecting to upstream, client: my.secret.ip.addr, server: nginxproxymanager, request: "POST /api/tokens HTTP/1.1", upstream: "http://127.0.0.1:3000/tokens", host: "10.0.51.101:81", referrer: "http://10.0.51.101:81/login"
[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] done.
[services.d] starting services
[services.d] done.
[3/27/2020] [3:34:46 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:34:57 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:35:08 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:35:19 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:35:30 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:35:41 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT
[3/27/2020] [3:35:52 PM] [Global   ] ຸ0>º ູC><96>  error     connect ETIMEDOUT

@jtmoree-github.aaakk.us.kg

Seconding @bookandrelease's sentiments here -- @donmccoy is right that the config.json is clearly outlined in the full setup, but it is notably absent from the quick setup which is also linked from the

I can't find any instructions for config.json in quick or Full Setup. (google can't find it either when I use it to search https://nginxproxymanager.com)
https://nginxproxymanager.com/setup/
https://nginxproxymanager.com/#quick-setup

The only reference is in the compose yaml file in full setup and it says to look somewhere that does not exist
# Make sure this config.json file exists as per instructions above:

I deleted the config.json line in compose and it comes up. I'll see what it looks like inside the container and try to recreate myself.... looks like it has jwt keys in it? that's hard to create since I dont know what these keys are....

@brantje
Copy link

brantje commented Jun 3, 2020

Something is broken, i used the quick setup and got the same error as shown above:
image

@sadri-fertani
Copy link

it works nice now for me after three changes
1 - create a config.json is in same folder of docker-compose.yml
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}
2 - change the first item of volumes in docker-compose file to use this new file => - ./config.json:/config.json
3 - change docker compose file by using another image of database 'image: 'mysql:5.7''
and don't forget to clean this directory './data/mysql/'

@evan-swinney
Copy link

I'm getting the same issue. Changing to another database did not solve the problem. I have been running Nginx-Proxy-Manager for about a year now and recently after a restart of the container it started doing this. Since then, I've completely wiped everything (even the OS due to another reason) and pulled the latest image using the full installation guide. The problem persists with getting Bad Gateway on the login screen as well as the same ECONNREFUSED error in the Docker logs as @brantje .

Additionally, in the health check, it has the error: parse error: Invalid numeric literal at line 1, column 7 NOT OK

Does anybody have a fix for this?

@rastacalavera
Copy link

I think I may have a solution. I had a similar issue with a bad gateway. This happened when I lost power to my pi4 and powered it back on. Here is my original docker-compose file with the actual user and password information replaced with the original setup (replace with your own):

version: '3'
services:
  proxy:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./config.json:/app/config/production.json
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
  db:
    image: 'yobasystems/alpine-mariadb'
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

So how I fixed the gateway issues is that I had to run docker-compose up -d proxy db
I had to bring up the database again because it wasn't coming up on its own. I think to fix this for future issues, I will add in a restart field into the compose file after the volumes section. so it would look something like this:

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

I am adding this because lots of my other containers have that same piece and they all came up fine and were accessible with their local ip and port even when I couldn't log into nginx proxy manager. Hopefully this will resolve the issue if I lose power again.

@badincite
Copy link

Fixed my by changing the db host from "db" to the local ip.

@devcircus
Copy link

I'm sure there are many reasons for these errors, but I was getting this same one: "parse error: Invalid numeric literal at line 1, column 7 NOT OK"
It took a couple of hours to realize I was missing the end brace in my config.json file.
Using Portainer, I clicked on the unhealthy container and pulled up the logs and it pointed me in the right direction.

@TLT93
Copy link

TLT93 commented Oct 28, 2020

I solved it by changing the docker-compose.yml file:

db: image: 'jc21/mariadb-aria:latest'

instead of

db: image: 'jc21/mariadb-aria:10.4'

@harveydobson
Copy link

harveydobson commented Nov 19, 2020

I've been getting the same, none of the above fixing it. Even with the new docker compose setup where environment variables are used instead of a config.json. https://nginxproxymanager.com/setup/

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      # If you would rather use Sqlite uncomment this
      # and remove all DB_MYSQL_* lines above
      # DB_SQLITE_FILE: "/data/database.sqlite"
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: jc21/mariadb-aria:10.4
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

@jc21
Copy link
Member

jc21 commented Nov 20, 2020

@harveydobson Just brought up a stack using the exact docker-compose file you posted and it's working fine. Admittedly I'm not using any pre-existing data though.

@harveydobson
Copy link

Hi @jc21,

Can I say firstly, NPM is absolutely amazing thank you so much for bringing this into existence!

I should have added more details to the above comment...

With regards to this issue, so I think the docker-compose set-up that I've copied from the set-up guide would work fine using real docker-compose. Just like the op, I am using portainer. I simply shared the above docker-compose content to illustrate the use of the environment variables instead of a config.json, as that was the reason that some had the issue.

(It's different to the one i used originally so i thought posting for reference could be useful to someone else in the future)

The core issue is that portainer doesn't share the hostnames of the containers, so certain modifications have to be made for it to work, the configuration that actually wasn't working was something like this:

(originally I was using a completely separate maria db set-up which was far more similar to the below, but this didn't work either)

version: "2.9" #portainer doesn't support > 2
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "192.168.1.112". #local IP of host machine
      DB_MYSQL_PORT: 9906
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      # If you would rather use Sqlite uncomment this
      # and remove all DB_MYSQL_* lines above
      # DB_SQLITE_FILE: "/data/database.sqlite"
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: jc21/mariadb-aria:10.4
    restart: always
    ports:
      - '9906:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

Even this generates the same connect ETIMEDOUT error.

In the end, I gave up and set the database to use the docker network IP address for the database server. This is not ideal as it could change... but i figure NPM will work fine without the database, it's only needed to edit the config which is not done very frequently. So I can simply update each time.

My biggest issue here is that I am using a Terramaster NAS that doesn't support docker-compose, and portainer doesn't support docker-compose fully, so i'm between a rock and a hard place :-D

@harveydobson
Copy link

harveydobson commented Nov 20, 2020

So yeah in summary, portainer can't seem to communicate on docker hostnames, this I already knew.

Oddly, I can't seem to get NPM to communicate outside of the docker network. Not sure if this is a side effect of the 'docker stack' concept? But a bit frustrating to say the least :-D

Edit: I think this could be a networking limitation of my TNAS.

@harveydobson
Copy link

To confirm from the above, please disregard my issue, it does seem to be something strange with the TNAS networking. I have installed a new OS on there and it's all working without a problem.

@wimmme
Copy link

wimmme commented Dec 3, 2020

For me on a RPI 3 running Hypriot

db:
image: mariadb:latest

does not work, but this does:

db:
image: yobasystems/alpine-mariadb:armhf

@anselal
Copy link

anselal commented Jan 4, 2021

@wimmme did not work on my rpi2

@teslakoil
Copy link

Hey folks,

So JSON file or not, and whichever DB variant I try, I'm getting the same result:

connect ECONNREFUSED 172.18.0.2:3306

@peterweissdk
Copy link

Im on a Raspberry Pi 3

I got this from docker ps, under ports:
0.0.0.0:80-81->80-81/tcp, 0.0.0.0:443->443/tcp
So I change the port to external 83 -> internal 81, and docker ps gave me this:
0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:83->81/tcp

Then i changed the database to mariadb:latest, but the rest of the docker-compose file is untouched.
Then I had to wait about 2-3 minutes, until the container became "healthy"
Docker ps gave me this:
Status: Up 49 seconds (unhealthy)
Then after a minute, docker ps gave me this:
Status: Up About a minute (healthy)

Then I was able to log in using port 83: http://ip_addr:83

Hope it clear things up.

@anselal
Copy link

anselal commented Jan 7, 2021

@peterweissdk already tried that. did not work for me

@ghost
Copy link

ghost commented Jan 19, 2021

Also getting this - raspberry pi 4b 4gb - tried all solutions still get parse error: Invalid numeric literal at line 1, column 7 NOT OK

@anselal
Copy link

anselal commented Jan 19, 2021

After a low of troubles someone suggested the following config. The difference is that is uses another container for the database that supports arm and I think that the important thing is the is uses version 2 instead of 3.

version: "2"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: yobasystems/alpine-mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

@ghost
Copy link

ghost commented Jan 19, 2021

@ anselal Thank you so much! After a few attempts to modify this, this worked. Thank you and everybody for figuring this out!

@anselal
Copy link

anselal commented Jan 19, 2021

@jc21 maybe add this dockerfile to your documentation ???

@REMINJOSE
Copy link

@anselal You are a life saver

@anselal
Copy link

anselal commented Jan 27, 2021

thnx goes to MichaIng/DietPi#1622 (comment)

@jc21 jc21 closed this as completed Feb 8, 2021
@bitsvital
Copy link

I wanted to leave a quick comment. I had a client that called me needing help. When I checked they were also receiving the Bad Gateway error. The first thing I did as it was over Zoom was a quick Google search which was the first page that I found. Someone commented earlier that there is multiple reasons why. They were on a slow connection. I finally was able to get to their logs. I realized what happened. They already had a MariaDB container running on part 3306 for WordPress. Once I stop that container rebuilt the NGINX-Proxy-Manager everything worked fine. I thought I'd add this incase someone in the future came across this same problem as I did.

@synergiator
Copy link

maybe this it trivial but if you start renaming services names, double check for the UI container to reference properly the db container hostname. I realized this gotcha after checking container logs:


> docker logs service_name
[4/8/2021] [8:37:55 PM] [Global   ] › ✖  error     getaddrinfo ENOTFOUND db

@balintszabo92
Copy link

After a low of troubles someone suggested the following config. The difference is that is uses another container for the database that supports arm and I think that the important thing is the is uses version 2 instead of 3.

version: "2"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: yobasystems/alpine-mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

Broo you have ended my sufferings I was trying to setup my home server for a month now, as soon as I used your example it was working. Thank you so much! Ευχαριστώ πολύ!

@anselal
Copy link

anselal commented May 3, 2021

After a low of troubles someone suggested the following config. The difference is that is uses another container for the database that supports arm and I think that the important thing is the is uses version 2 instead of 3.

version: "2"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: always
    ports:
      # Public HTTP Port:
      - '80:80'
      # Public HTTPS Port:
      - '443:443'
      # Admin Web Port:
      - '81:81'
    environment:
      # These are the settings to access your db
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
  db:
    image: yobasystems/alpine-mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

Broo you have ended my sufferings I was trying to setup my home server for a month now, as soon as I used your example it was working. Thank you so much! Ευχαριστώ πολύ!

να είσαι καλά αδερφέ, και εμένα μου έλυσα τα χέρια αν και στην τελική το κάνω με custom ρυθμίσεις στον nginx

@Subline-75
Copy link

What I needed to work this it out (bad gateway on the login page):
https://www.youtube.com/watch?v=ZrS3IT7HG2Y&

Create my first SQL user & database : 👍

@FreshImmuc
Copy link

docker-compose up -d created a directory config.json/ instead of a file.
stop containers
sudo rm -r config.json directory
create config.json file with:
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}

YOOOO THANKS SOO MUCH DUDE THIS HELPED ME SO MUCH

@japatel5213
Copy link

image
Same Issue.
I was used this script.

version: '3'

services:
  # Database
  db:
    image: mysql:latest
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 009.Jnvekariya
      MYSQL_DATABASE: wordpress
      MYSQL_USER: jaypatel5213
      MYSQL_PASSWORD: 009.Jnvekariya
    networks:
      - tecis
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: 009.Jnvekariya
    networks:
      - tecis
  # Wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '80:80'
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: jaypatel5213
      WORDPRESS_DB_PASSWORD: 009.Jnvekariya
    networks:
      - tecis
  # NPM
  npm:
    depends_on:
      - db
    image: jc21/nginx-proxy-manager:latest
    ports:
      - '90:90'
      - '443:443'
      - '81:81'
    restart: always
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    environment:
      DB_MYSQL_HOST: db
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: jaypatel5213
      DB_MYSQL_PASSWORD: 009.Jnvekariya
      DB_MYSQL_NAME: npm
    networks:
      - tecis
networks:         
  tecis:
volumes:
  db_data:

Above Script for WordPress, NPM, PHPMyAdmin, And MySQL Database.
WordPress, PHPMyAdmin, and MySQL are Working Fine but NPM is Shown ERROR.
Any One Idea how to NPM Configer to MySQL.

@tjwebb
Copy link

tjwebb commented Aug 28, 2021

But I'm pretty sure you just didn't create config.json which is stated so clearly in the docs

@DonSYS91 where is this documented? certainly not in Quick Setup: https://nginxproxymanager.com/guide/#quick-setup

@chaptergy chaptergy changed the title Bad Gateway at Admin Page Bad Gateway at Admin Page: production.json cannot be read Nov 5, 2021
@chaptergy
Copy link
Collaborator

As this is a fairly old issue and contains some outdated information, like the config.json which is no longer the default way to set things up, I'll lock this issue.
For anyone stumbling on this issue: A Bad Gateway when trying to log in is 90% of the time an issue with the database either not running or the connection to the database failing. See #1271 (comment)

@NginxProxyManager NginxProxyManager locked as resolved and limited conversation to collaborators Nov 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests