Bad Gateway 502
Did everything as it is described in the readme (for HTTP at 127.0.0.1), all containers are running fine, but I get a 502 as soon as I load the host-url via browser.
There are a few issues mentioned in the web like https://stackoverflow.com/questions/47429540/nginx-502-bad-gateway-within-docker-stack but none of the suggestions helped so far.
Any idea to solve that issue?
Best regards
@phonic - Hard to say without getting some more information from you.
Things to look at:
- make sure all containers are running and not restarting on you
- review that stdout of the containers via
docker-compose logsordocker logs CONTAINER_NAME. Hopefully there is some indication of the issue being encountered. - Permissions / ownership of the directories being shared with the containers. If there is a permissions mismatch the processes running wordpress may not be able to access the files.
- ports already being used by other processes
Feel free to post log output or other info that may help debug back to this thread.
- platform you're running on
-
docker-compose.ymlthat you're using - output from
docker ps -a - output from
docker logs ...
Hey @mjstealey
I did everything exactly as it was described from the instructions for localhost development (especially regarding .conf without SSL). Containers are running fine so far...
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
327174346fde nginx:latest "nginx -g 'daemon of…" 7 minutes ago Up 7 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx
993c7479b021 wordpress:php7.2-fpm "docker-entrypoint.s…" 7 minutes ago Up 22 seconds 9000/tcp wordpress
7649305ef2f5 mariadb "docker-entrypoint.s…" 7 minutes ago Restarting (1) 46 seconds ago mysql
...and I can connect to the container via
$ winpty docker exec -it 327174346fde bash
root@327174346fde:/#
After installing curl on the nginx container, the following command results with 502
root@327174346fde:/# curl localhost:80
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.15.7</center>
</body>
</html>
Logically, I cannot connect to the wp instance from windows host as well
A clean nginx container however (without WP/MySQL) results in a successful curl.
I'm running on docker for windows.
Thank you for the updated info.
Containers are running fine so far...
It looks like the mysql container that runs MariaDB is restarting. And unless you explicitly issued a restart call it should not be doing this, and would be something to look at.
- look at the output of
docker logs mysql - check permissions of the underlying volume mount (
mysqlfolder) - if stale data from a prior run that wasn't purged before starting a new run (delete all volume mounts and recreate between runs)
- had you tried a modified user/pass of the MariaDB instance? (non-root user example) It may be problematic if switching back and forth between examples without purging volumes between runs
After installing curl on the nginx container, the following command results with 502
It does look like Nginx is doing it's job in that you are getting a response served from Nginx. Hard to say if the Wordpress container is working, but if the database is not being recognized, then the Wordpress container would be non-functional, but still running.
- look at the output of
docker logs wordpressfor clues
I'm running on docker for windows.
Unfortunately I do not have access to a bare metal Windows box to test. I could spin up a Windows VM, but then would be using nested virtualization and may not be equivalent to what you are working with...
it seems the issue is a php related one. The 502 is gone away when you index any html file
In this case a bad gateway (502) error makes sense if the Wordpress container is unable to properly serve content.
I still think the database may be the culprit in that Wordpress cannot interact with it because it's in a restarting loop/state and unable to serve the content that would normally be regulated by the database.
I'm using macOS, so a sample http local deploy would be:
git clone https://github.com/mjstealey/wordpress-nginx-docker.git
cd wordpress-nginx-docker
mkdir -p certs/ certs-data/ logs/nginx/ mysql/ wordpress/
cp nginx/wordpress.conf.example nginx/wordpress.conf
vi nginx/wordpress.conf ### update: server_name 127.0.0.1;
docker-compose up -d
Running state:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1efa13b8fdb nginx:latest "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx
d50a35575abc wordpress:php7.2-fpm "docker-entrypoint.s…" About a minute ago Up About a minute 9000/tcp wordpress
ba03d698e7b6 mariadb "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp mysql
A healthy mysql log would look like:
$ docker logs mysql
Initializing database
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h password 'new-password'
Alternatively you can run:
'/usr/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Database initialized
MySQL init process in progress...
2018-12-06 12:54:18 0 [Note] mysqld (mysqld 10.3.11-MariaDB-1:10.3.11+maria~bionic) starting as process 106 ...
2018-12-06 12:54:18 0 [Note] InnoDB: Using Linux native AIO
2018-12-06 12:54:18 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-12-06 12:54:18 0 [Note] InnoDB: Uses event mutexes
2018-12-06 12:54:18 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-12-06 12:54:18 0 [Note] InnoDB: Number of pools: 1
2018-12-06 12:54:18 0 [Note] InnoDB: Using SSE2 crc32 instructions
2018-12-06 12:54:18 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-12-06 12:54:18 0 [Note] InnoDB: Completed initialization of buffer pool
2018-12-06 12:54:18 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-12-06 12:54:18 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-12-06 12:54:18 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-12-06 12:54:18 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
MySQL init process in progress...
2018-12-06 12:54:19 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-12-06 12:54:19 0 [Note] InnoDB: 10.3.11 started; log sequence number 1630824; transaction id 21
2018-12-06 12:54:19 0 [Note] Plugin 'FEEDBACK' is disabled.
2018-12-06 12:54:19 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-12-06 12:54:19 0 [Note] InnoDB: Buffer pool(s) load completed at 181206 12:54:19
2018-12-06 12:54:19 0 [Warning] 'user' entry 'root@ba03d698e7b6' ignored in --skip-name-resolve mode.
2018-12-06 12:54:19 0 [Warning] 'user' entry '@ba03d698e7b6' ignored in --skip-name-resolve mode.
2018-12-06 12:54:19 0 [Warning] 'proxies_priv' entry '@% root@ba03d698e7b6' ignored in --skip-name-resolve mode.
2018-12-06 12:54:19 0 [Note] Reading of all Master_info entries succeded
2018-12-06 12:54:19 0 [Note] Added new Master_info '' to hash table
2018-12-06 12:54:19 0 [Note] mysqld: ready for connections.
Version: '10.3.11-MariaDB-1:10.3.11+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
2018-12-06 12:54:35 10 [Warning] 'proxies_priv' entry '@% root@ba03d698e7b6' ignored in --skip-name-resolve mode.
2018-12-06 12:54:35 0 [Note] mysqld (initiated by: unknown): Normal shutdown
2018-12-06 12:54:35 0 [Note] Event Scheduler: Purging the queue. 0 events
2018-12-06 12:54:35 0 [Note] InnoDB: FTS optimize thread exiting.
2018-12-06 12:54:35 0 [Note] InnoDB: Starting shutdown...
2018-12-06 12:54:35 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2018-12-06 12:54:35 0 [Note] InnoDB: Buffer pool(s) dump completed at 181206 12:54:35
2018-12-06 12:54:36 0 [Note] InnoDB: Shutdown completed; log sequence number 1630833; transaction id 24
2018-12-06 12:54:36 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2018-12-06 12:54:37 0 [Note] mysqld: Shutdown complete
MySQL init process done. Ready for start up.
2018-12-06 12:54:37 0 [Note] mysqld (mysqld 10.3.11-MariaDB-1:10.3.11+maria~bionic) starting as process 1 ...
2018-12-06 12:54:37 0 [Note] InnoDB: Using Linux native AIO
2018-12-06 12:54:37 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-12-06 12:54:37 0 [Note] InnoDB: Uses event mutexes
2018-12-06 12:54:37 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-12-06 12:54:37 0 [Note] InnoDB: Number of pools: 1
2018-12-06 12:54:37 0 [Note] InnoDB: Using SSE2 crc32 instructions
2018-12-06 12:54:37 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-12-06 12:54:37 0 [Note] InnoDB: Completed initialization of buffer pool
2018-12-06 12:54:37 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-12-06 12:54:37 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-12-06 12:54:37 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-12-06 12:54:37 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-12-06 12:54:38 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-12-06 12:54:38 0 [Note] InnoDB: 10.3.11 started; log sequence number 1630833; transaction id 21
2018-12-06 12:54:38 0 [Note] Plugin 'FEEDBACK' is disabled.
2018-12-06 12:54:38 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-12-06 12:54:38 0 [Note] Server socket created on IP: '::'.
2018-12-06 12:54:38 0 [Note] InnoDB: Buffer pool(s) load completed at 181206 12:54:38
2018-12-06 12:54:38 0 [Warning] 'proxies_priv' entry '@% root@ba03d698e7b6' ignored in --skip-name-resolve mode.
2018-12-06 12:54:38 0 [Note] Reading of all Master_info entries succeded
2018-12-06 12:54:38 0 [Note] Added new Master_info '' to hash table
2018-12-06 12:54:38 0 [Note] mysqld: ready for connections.
Version: '10.3.11-MariaDB-1:10.3.11+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
And finally a check of http://127.0.0.1
@mjstealey I really appreciate your help! Thanks for it, will looking into it!
@mjstealey
Solved the problem by removing the volume mount for mysql from docker-compose.
volumes:
- ./mysql:/var/lib/mysql
Otherwise I would get the following error log messages:
mysql | 2018-12-06 14:44:39 0 [ERROR] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size 0 pages than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
mysql | 2018-12-06 14:44:39 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
mysql | 2018-12-06 14:44:40 0 [Note] InnoDB: Starting shutdown...
mysql | 2018-12-06 14:44:40 0 [ERROR] Plugin 'InnoDB' init function returned error.
mysql | 2018-12-06 14:44:40 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysql | 2018-12-06 14:44:40 0 [Note] Plugin 'FEEDBACK' is disabled.
mysql | 2018-12-06 14:44:40 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
mysql | 2018-12-06 14:44:40 0 [ERROR] Unknown/unsupported storage engine: InnoDB
mysql | 2018-12-06 14:44:40 0 [ERROR] Aborting
I am using a mac too and I ran into the same problem and I use a docker volume instead. It might have something to do with the file system. This approach might be easier to back up the database.
mysql:
volumes:
- db_data:/var/lib/mysql
......
volumes:
db_data: