meanbee / docker-magento2

🐳 Docker containers with all required Magento 2 dependencies installed available as FPM through Nginx and CLI
MIT License
454 stars 244 forks source link

502 Bad Gateway after set-up #130

Closed benhtn closed 1 year ago

benhtn commented 6 years ago

Hi there, I am running this on a macbook with High Sierra, and Docker CE Version 18.06.0-ce-mac70 (26399).

I completed the quick set-up (all seemed fine with the magento installer), then guessing from the output of docker ps, I visited http://localhost:32798 But I get 502 Bad Gateway - nginx/1.9.15

I also added a /etc/hosts entry to point to 127.0.0.1 magento2.docker And tried visiting http://magento2.docker:32798 But still the same.

I can see varnish running usingthe varnishlog command in the varnish container. I see the 502 error there too. e.g.

# varnishlog
*   << BeReq    >> 32774
-   Begin          bereq 32773 fetch
-   Timestamp      Start: 1535393431.384210 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /
-   BereqProtocol  HTTP/1.1
-   BereqHeader    Host: magento2.docker:32798
-   BereqHeader    Pragma: no-cache
-   BereqHeader    Upgrade-Insecure-Requests: 1
-   BereqHeader    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
-   BereqHeader    DNT: 1
-   BereqHeader    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
-   BereqHeader    Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
-   BereqHeader    X-Forwarded-For: 172.23.0.1
-   BereqHeader    Accept-Encoding: gzip
-   BereqHeader    X-Varnish: 32774
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendClose   17 default(172.23.0.6,,80) toolate
-   BackendOpen    17 default(172.23.0.6,,80) 172.23.0.7 39786
-   Backend        17 default default(172.23.0.6,,80)
-   Timestamp      Bereq: 1535393431.384616 0.000406 0.000406
-   Timestamp      Beresp: 1535393434.546414 3.162204 3.161798
-   BerespProtocol HTTP/1.1
-   BerespStatus   502
-   BerespReason   Bad Gateway
-   BerespHeader   Server: nginx/1.9.15
-   BerespHeader   Date: Mon, 27 Aug 2018 18:10:34 GMT
-   BerespHeader   Content-Type: text/html; charset=UTF-8
-   BerespHeader   Content-Length: 575
-   BerespHeader   Connection: keep-alive
-   TTL            RFC -1 -1 -1 1535393435 1535393435 1535393434 0 0
-   VCL_call       BACKEND_RESPONSE
-   TTL            VCL 0 3600 0 1535393435
-   VCL_return     deliver
-   BerespHeader   Content-Encoding: gzip
-   BerespUnset    Content-Length: 575
-   Storage        malloc Transient
-   ObjProtocol    HTTP/1.1
-   ObjStatus      502
-   ObjReason      Bad Gateway
-   ObjHeader      Server: nginx/1.9.15
-   ObjHeader      Date: Mon, 27 Aug 2018 18:10:34 GMT
-   ObjHeader      Content-Type: text/html; charset=UTF-8
-   ObjHeader      Content-Encoding: gzip
-   Fetch_Body     3 length -
-   Gzip           G F E 575 199 80 1512 1522
-   BackendReuse   17 default(172.23.0.6,,80)
-   Timestamp      BerespBody: 1535393434.546953 3.162743 0.000539
-   Length         199
-   BereqAcct      448 0 448 172 575 747
-   End

I tried disabling varnish (removing the block in docker-compose.yml and add the block for nginx), but after restart I cannot access anything (port 80 - refused to connect). I can see nginx is running in the web container:

# service nginx status
[ ok ] nginx is running.

Can you give me any ideas/ can I provide further information to assist diagnosis?

Alexander0Sh commented 6 years ago

docker inspect docker-magento2_web_1. The value of the field "IPAddress" write to the hosts file. For example 172.18.0.3 magento2.docker

benhtn commented 6 years ago

Many thanks for the response @Aleksanteris. I tried running inspect on the web container and got this:

                    "IPAMConfig": null,
                    "Links": [
                        "meanbee_db_1:db",
                        "meanbee_db_1:db_1",
                        "meanbee_db_1:meanbee_db_1",
                        "meanbee_fpm_1:fpm",
                        "meanbee_fpm_1:fpm_1",
                        "meanbee_fpm_1:meanbee_fpm_1"
                    ],
                    "Aliases": [
                        "web",
                        "613a7b9b08b9"
                    ],
                    "NetworkID": "5a6d65aa73dedc65fc2eac7ead3231409e4ff38e7626461b1093973441ac66ea",
                    "EndpointID": "d69da04562536b812caf909b89374fcb1030477ce72ed14c0ceb51546900670e",
                    "Gateway": "192.168.0.1",
                    "IPAddress": "192.168.0.6",
                    "IPPrefixLen": 20,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:c0:a8:00:06",
                    "DriverOpts": null

So I added this to /etc/hosts:

192.168.0.6     magento2.docker

Checking the docker containers with $ docker ps -a | grep meanbee

$ docker ps -a | grep meanbee
621de4c49d8c        meanbee/magento2-varnish:latest    "/bin/sh -c /start.sh"   13 minutes ago      Up 18 seconds                    0.0.0.0:32802->80/tcp                         meanbee_varnish_1
613a7b9b08b9        meanbee/magento2-nginx:1.9         "/usr/local/bin/dock…"   13 minutes ago      Up 19 seconds                    443/tcp, 0.0.0.0:32801->80/tcp                meanbee_web_1
29f7ea4817b1        meanbee/magento2-php:7.0-cli       "/docker-entrypoint.…"   13 minutes ago      Up 23 seconds                                                                  meanbee_cli_1
1b71aeff860e        meanbee/magento2-php:7.0-fpm       "/docker-entrypoint.…"   13 minutes ago      Up 23 seconds                    0.0.0.0:32800->9000/tcp                       meanbee_fpm_1
a39c923eefb2        meanbee/magento2-php:7.0-cli       "/docker-entrypoint.…"   13 minutes ago      Up 13 seconds                                                                  meanbee_cron_1
f9ed7e5913b6        meanbee/magento2-php:7.0-cli       "/docker-entrypoint.…"   About an hour ago   Exited (0) 13 minutes ago                                                      meanbee_cli_run_1
82ca2bc925a4        mariadb:10                         "docker-entrypoint.s…"   About an hour ago   Up 18 seconds                    0.0.0.0:32803->3306/tcp                       meanbee_db_1
0b7edf773bd9        tianon/true                        "/true"                  About an hour ago   Exited (0) 23 seconds ago                                                      meanbee_dbdata_1
1ede28e8a4ae        tianon/true                        "/true"                  About an hour ago   Exited (0) 23 seconds ago                                                      meanbee_appdata_1

Which looks about right doesn't it?

However I got still get "magento2.docker refused to connect. " in my browser from http://magento2.docker and http://magento2.docker:32796/ and "Bad gatway from http://192.168.1.80:32801/ and http://192.168.1.80:32802/

I am getting to the varnish container with http://192.168.1.80:32802/ because I see it in the logs, but how to I diagnose the "Bad Gateway" response please?

benhtn commented 6 years ago

Got this from running docker logs on the web container:


2018/08/28 18:19:19 [error] 14#14: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://192.168.0.9:9000", host: "192.168.1.80:32801", referrer: "http://192.168.1.80:32801/
ygrigoriev commented 6 years ago

Hey guys, I have the same issue on High Sierra; is there some news on it?

alexeyplumtreegroup commented 6 years ago

set UPDATE_UID_GID=false in the global.env

tgamanov commented 6 years ago

Also, have this issue. Tried docker inspect docker-magento2_web_1 and set UPDATE_UID_GID=false in the global.env does not helpred.

punkstar commented 6 years ago

I'm not aware of anything specifically wrong with High Sierra. I've been using these images on that version of the OS without problem for a while.

DominicWatts commented 6 years ago

Running Windows 10. Exact same problems as described.

set UPDATE_UID_GID=false in the global.env

This worked for me. Remembering the quickstart asks you to create composer.env

pmuaddib commented 6 years ago

Same error for me

benvansteenbergen commented 6 years ago

Hi,

seems to be related to the php container version used by default in docker-compose.yml. If you replace 7.0 by 7.1 (meanbee/magento2-php:7.0-xxx->meanbee/magento2-php:7.1-xxx), it will get to work (tested on MacOS Sierra).

Update: php7.1 does not support Mcrypt which causes an error. There are several patches available as the problem is caused only by one file. Like DominicWatts states below magento2/issues/5880 php7.2 is not supported by M2 until 2.3

Good luck,

itsazzad commented 6 years ago

@benvansteenbergen with 7.1:

Exception: Deprecated Functionality: Function mcrypt_module_open() is deprecated in /var/www/magento/vendor/magento/framework/Encryption/Crypt.php on line 54 in /var/www/magento/vendor/magento/framework/App/ErrorHandler.php:61 Stack trace: #0 /var/www/magento/vendor/magento/framework/Encryption/Crypt.php(54): Magento\Framework\App\ErrorHandler->handler(8192, 'Function mcrypt...', '/var/www/magent...', 54, Array) #1 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(401): Magento\Framework\Encryption\Crypt->__construct('7df168579fa9b19...', 'rijndael-256', 'cbc', 'LBpXrigtHVWVcz4...') #2 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(313): Magento\Framework\Encryption\Encryptor->getCrypt('7df168579fa9b19...', 2, 'LBpXrigtHVWVcz4...') #3 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(228): Magento\Framework\Encryption\Encryptor->decrypt('LFMaYNX/ACJBRit...') #4 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(180): Magento\Config\App\Config\Type\System->loadDefaultScopeData('default') #5 /var/www/magento/vendor/magento/framework/App/Config.php(139): Magento\Config\App\Config\Type\System->get('default/web/sec...') #6 /var/www/magento/vendor/magento/framework/App/Config.php(90): Magento\Framework\App\Config->get('system', 'default/web/sec...') #7 /var/www/magento/vendor/magento/framework/App/Config.php(103): Magento\Framework\App\Config->getValue('web/secure/use_...', 'default', NULL) #8 /var/www/magento/vendor/magento/module-store/Model/HeaderProvider/Hsts.php(48): Magento\Framework\App\Config->isSetFlag('web/secure/use_...') #9 /var/www/magento/vendor/magento/framework/App/Response/HeaderManager.php(41): Magento\Store\Model\HeaderProvider\Hsts->canApply() #10 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(123): Magento\Framework\App\Response\HeaderManager->beforeSendResponse(Object(Magento\Framework\App\Response\Http\Interceptor)) #11 /var/www/magento/var/generation/Magento/Framework/App/Response/Http/Interceptor.php(117): Magento\Framework\App\Response\Http\Interceptor->___callPlugins('sendResponse', Array, Array) #12 /var/www/magento/vendor/magento/framework/App/Http.php(185): Magento\Framework\App\Response\Http\Interceptor->sendResponse() #13 /var/www/magento/vendor/magento/framework/App/Http.php(156): Magento\Framework\App\Http->handleDeveloperMode(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #14 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http->catchException(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #15 /var/www/magento/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #16 {main}
itsazzad commented 6 years ago

@benvansteenbergen and with 7.2: Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /var/www/magento/vendor/colinmollenhour/cache-backend-file/File.php on line 81 Exception: Warning: Use of undefined constant MCRYPT_RIJNDAEL_256 - assumed 'MCRYPT_RIJNDAEL256' (this will throw an Error in a future version of PHP) in /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php on line 394 in /var/www/magento/vendor/magento/framework/App/ErrorHandler.php:61 Stack trace: #0 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(394): Magento\Framework\App\ErrorHandler->handler(2, 'Use of undefine...', '/var/www/magent...', 394, Array) #1 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(313): Magento\Framework\Encryption\Encryptor->getCrypt('7df168579fa9b19...', 2, 'LBpXrigtHVWVcz4...') #2 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(228): Magento\Framework\Encryption\Encryptor->decrypt('LFMaYNX/ACJBRit...') #3 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(180): Magento\Config\App\Config\Type\System->loadDefaultScopeData('default') #4 /var/www/magento/vendor/magento/framework/App/Config.php(139): Magento\Config\App\Config\Type\System->get('default/web/sec...') #5 /var/www/magento/vendor/magento/framework/App/Config.php(90): Magento\Framework\App\Config->get('system', 'default/web/sec...') #6 /var/www/magento/vendor/magento/framework/App/Config.php(103): Magento\Framework\App\Config->getValue('web/secure/use...', 'default', NULL) #7 /var/www/magento/vendor/magento/module-store/Model/HeaderProvider/Hsts.php(48): Magento\Framework\App\Config->isSetFlag('web/secure/use_...') #8 /var/www/magento/vendor/magento/framework/App/Response/HeaderManager.php(41): Magento\Store\Model\HeaderProvider\Hsts->canApply() #9 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(123): Magento\Framework\App\Response\HeaderManager->beforeSendResponse(Object(Magento\Framework\App\Response\Http\Interceptor)) #10 /var/www/magento/var/generation/Magento/Framework/App/Response/Http/Interceptor.php(117): Magento\Framework\App\Response\Http\Interceptor->___callPlugins('sendResponse', Array, Array) #11 /var/www/magento/vendor/magento/framework/App/Http.php(185): Magento\Framework\App\Response\Http\Interceptor->sendResponse() #12 /var/www/magento/vendor/magento/framework/App/Http.php(156): Magento\Framework\App\Http->handleDeveloperMode(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #13 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http->catchException(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #14 /var/www/magento/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #15 {main}

DominicWatts commented 6 years ago

Magento 2 itself is not compatible with php 7.2

I believe it's something they're working on as part of 2.3 release

They've got a lot to update though!

https://github.com/magento-engcom/php-7.2-support

molejnik-mergebit commented 5 years ago

@benvansteenbergen with 7.1:

Exception: Deprecated Functionality: Function mcrypt_module_open() is deprecated in /var/www/magento/vendor/magento/framework/Encryption/Crypt.php on line 54 in /var/www/magento/vendor/magento/framework/App/ErrorHandler.php:61 Stack trace: #0 /var/www/magento/vendor/magento/framework/Encryption/Crypt.php(54): Magento\Framework\App\ErrorHandler->handler(8192, 'Function mcrypt...', '/var/www/magent...', 54, Array) #1 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(401): Magento\Framework\Encryption\Crypt->__construct('7df168579fa9b19...', 'rijndael-256', 'cbc', 'LBpXrigtHVWVcz4...') #2 /var/www/magento/vendor/magento/framework/Encryption/Encryptor.php(313): Magento\Framework\Encryption\Encryptor->getCrypt('7df168579fa9b19...', 2, 'LBpXrigtHVWVcz4...') #3 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(228): Magento\Framework\Encryption\Encryptor->decrypt('LFMaYNX/ACJBRit...') #4 /var/www/magento/vendor/magento/module-config/App/Config/Type/System.php(180): Magento\Config\App\Config\Type\System->loadDefaultScopeData('default') #5 /var/www/magento/vendor/magento/framework/App/Config.php(139): Magento\Config\App\Config\Type\System->get('default/web/sec...') #6 /var/www/magento/vendor/magento/framework/App/Config.php(90): Magento\Framework\App\Config->get('system', 'default/web/sec...') #7 /var/www/magento/vendor/magento/framework/App/Config.php(103): Magento\Framework\App\Config->getValue('web/secure/use_...', 'default', NULL) #8 /var/www/magento/vendor/magento/module-store/Model/HeaderProvider/Hsts.php(48): Magento\Framework\App\Config->isSetFlag('web/secure/use_...') #9 /var/www/magento/vendor/magento/framework/App/Response/HeaderManager.php(41): Magento\Store\Model\HeaderProvider\Hsts->canApply() #10 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(123): Magento\Framework\App\Response\HeaderManager->beforeSendResponse(Object(Magento\Framework\App\Response\Http\Interceptor)) #11 /var/www/magento/var/generation/Magento/Framework/App/Response/Http/Interceptor.php(117): Magento\Framework\App\Response\Http\Interceptor->___callPlugins('sendResponse', Array, Array) #12 /var/www/magento/vendor/magento/framework/App/Http.php(185): Magento\Framework\App\Response\Http\Interceptor->sendResponse() #13 /var/www/magento/vendor/magento/framework/App/Http.php(156): Magento\Framework\App\Http->handleDeveloperMode(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #14 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http->catchException(Object(Magento\Framework\App\Bootstrap), Object(Exception)) #15 /var/www/magento/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #16 {main}

Same here. 7.1 is not working on High Sierra.

DominicWatts commented 5 years ago

This is a magento 2 issue

https://github.com/magento/magento2/issues/5880

molejnik-mergebit commented 5 years ago

After setting UPDATE_UID_GID=false in the global.env is it enough to call docker-compose restart? If so it didn't help... Trying to access IP from docker inspect docker-magento2_web_1 doesn't help either. Running High Sierra (without dinghy - as I red somewhere that this may be helpful but the setup can be run without it as well).

molejnik-mergebit commented 5 years ago

@benhtn did you manage to solve this issue? I have the same problem

molejnik-mergebit commented 5 years ago

@benvansteenbergen I recreated containers using php 7.1 (by setting meanbee/magento2-php:7.0-xxx->meanbee/magento2-php:7.1-xxx) and Magento 2.2 (by setting M2SETUP_VERSION=2.1. -> M2SETUP_VERSION=2.2.). And still I get 502 bad gateway. For me this is network issue, but I don't know how to solve it.

When issuing docker-compose ps should the container meanbee_appdata_1 be in Up state?

DominicWatts commented 5 years ago

docker-compose up -d

docker ps

docker-compose run --rm cli magento-command setup:store-config:set --base-url="http://magento2.docker:32785/"

http://magento2.docker:32785

molejnik-mergebit commented 5 years ago

@DominicWatts it looks like this helped, I managed to access magento webpage after setting this magic base-url. Thank you very much!

LiamKarlMitchell commented 5 years ago

Also have this problem, how do I fix it?

Console shows fpm_1 | Starting Mail Transport Agent (MTA): sendmail. fpm_1 | [07-Dec-2018 05:39:47] ERROR: [pool www] please specify user and group other than root fpm_1 | [07-Dec-2018 05:39:47] ERROR: [pool www] please specify user and group other than root fpm_1 | [07-Dec-2018 05:39:47] ERROR: FPM initialization failed fpm_1 | [07-Dec-2018 05:39:47] ERROR: FPM initialization failed cli_1 | Starting Mail Transport Agent (MTA): sendmail. cron_1 | Starting Mail Transport Agent (MTA): sendmail. docker-magento2_fpm_1 exited with code 78

docker-compose run --rm cli magento-command setup:store-config:set --base-url="http://magento2.docker:32803/"

Docker ps output.

λ docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                            NAMES
2f192e02c712        meanbee/magento2-varnish:latest   "/bin/sh -c /start.sh"   5 minutes ago       Up 5 minutes        0.0.0.0:32804->80/tcp            docker-magento2_varnish_1
74e25311650a        meanbee/magento2-nginx:1.9        "/usr/local/bin/dock…"   5 minutes ago       Up 5 minutes        443/tcp, 0.0.0.0:32803->80/tcp   docker-magento2_web_1
2843d38ba5e4        meanbee/magento2-php:7.0-cli      "/docker-entrypoint.…"   5 minutes ago       Up 5 minutes                                         docker-magento2_cron_1

So to fix I need PHP 7.1 and to apply the mcrypt patch to one file?

I have edited the php version in the docker-compose.yml and ran docker-compose down docker-compose up

Still getting this 502 Bad Gateway nginx/1.9.15

Magento 2.2.5

Docker PS output after changing to PHP 7.1.

λ docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED              STATUS              PORTS                            NAMES
eeafe90e1806        meanbee/magento2-varnish:latest   "/bin/sh -c /start.sh"   About a minute ago   Up About a minute   0.0.0.0:32809->80/tcp            docker-magento2_varnish_1
aae79066c24e        meanbee/magento2-nginx:1.9        "/usr/local/bin/dock…"   About a minute ago   Up About a minute   443/tcp, 0.0.0.0:32808->80/tcp   docker-magento2_web_1
84c2e9b9cdf4        meanbee/magento2-php:7.1-cli      "/docker-entrypoint.…"   About a minute ago   Up About a minute                                    docker-magento2_cron_1

docker-compose run --rm cli magento-command setup:store-config:set --base-url="http://magento2.docker:32808/"

Unable to connect on localhost port 80 either.

Edit:

UPDATE_UID_GID=false
ENABLE_SENDMAIL=false

In the global.env

And adding port 80 to varnish resolved.

  varnish:
    image: meanbee/magento2-varnish:latest
    environment:
      - VIRTUAL_HOST=magento2.docker
      - VIRTUAL_PORT=80
      - HTTPS_METHOD=noredirect
    ports:
      - "80:80"
    links:
      - web
benvansteenbergen commented 5 years ago

Try connecting localhost on port 32809 (see docker ps output). Or modify varnish port from 80 to 80:80 in your docker-compose.yml Good luck!

Verstuurd vanaf mijn iPhone

Op 7 dec. 2018 om 06:39 heeft Liam Mitchell notifications@github.com het volgende geschreven:

32809

molejnik-mergebit commented 5 years ago

@LiamKarlMitchell I'm using php 7.1. To avoid mcrypt issue I've just changed in docker-compose.yml line - M2SETUP_VERSION=2.1.* to - M2SETUP_VERSION=2.2.* because Magento 2.2 seems to be compatible with php 7.1

andyhoanghuu commented 4 years ago

Same error for me, PHP 7.4 and Magento 2.4

davidwindell commented 4 years ago

@ndoublehwp did you find a solution?