PrestaShop / docker

🐳
https://hub.docker.com/r/prestashop/prestashop/
MIT License
263 stars 181 forks source link

Prestashop 8.1 FPM with Nginx - 504 Gateway Timeout #352

Open exepowered opened 1 year ago

exepowered commented 1 year ago

Hi,

I am trying to get Prestashop 8.1 running on Docker as my dev environment, but I can't succeed. First I tried the prestashop:latest image with Apache web server and used Nginx as a SSL Proxy to run it over HTTPS. Everything worked fine until the Theme Installation step in the installer; I was getting 504 Gateway Time-out error. Running it just on Apache without Nginx didn't helped. Tried setting the proxy timeout limits to a higher value, still no luck.

I've decided to use FPM image instead. Now the Prestashop's docker log says that the FPM is listening for connections, my nginx server seems to be configured correctly, everything's up, but I get the 502 Bad Gateway error trying to open the installer via localhost in my browser...

Can someone help me with this one?

Docker log:

prestashop                       | [10-Aug-2023 02:44:23] NOTICE: fpm is running, pid 1

prestashop                       | [10-Aug-2023 02:44:23] NOTICE: ready to handle connections

shop-nginx-proxy-1  | 2023/08/10 02:46:31 [error] 29#29: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET / HTTP/2.0", upstream: "http://172.18.0.3:80/", host: "localhost"

shop-nginx-proxy-1  | 172.18.0.1 - - [10/Aug/2023:02:46:31 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "-"

shop-nginx-proxy-1  | 2023/08/10 02:46:31 [error] 29#29: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /favicon.ico HTTP/2.0", upstream: "http://172.18.0.3:80/favicon.ico", host: "localhost", referrer: "https://localhost/"

shop-nginx-proxy-1  | 172.18.0.1 - - [10/Aug/2023:02:46:31 +0000] "GET /favicon.ico HTTP/2.0" 502 559 "https://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "-"

My docker-compose.yml: I have all my .env values in correctly. "PS_DOMAIN" is set to "localhost".

version: '3'
services:

  nginx-proxy:  # Nginx web server
    image: nginx:latest  # Latest Nginx Server Image
    depends_on:
      - prestashop
    ports:
      - 80:80
      - 443:443
    networks:
      - prestashop_network
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf  # Mount the Nginx config
      - ./ssl:/etc/nginx/ssl  # Mount the SSL folder to provide certs

  mysql:  # MySQL DB
    container_name: mysql
    image: mysql:latest  # Latest MySQL Server Image
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWD}  # MySQL Root Password
      MYSQL_DATABASE: ${MYSQL_DATABASE}  # Project's database
      MYSQL_USER: ${MYSQL_USER}  # Project's database user
      MYSQL_PASSWORD: ${MYSQL_USER_PASSWD}  # Project's database password
    ports:
      - 3306:3306
    networks:
      - prestashop_network
    volumes:
      - mysql-data:/var/lib/mysql  # Mount the MySQL data volume

  prestashop:  # Prestashop Shop CMS
    container_name: prestashop
    # image: prestashop/prestashop:latest  # Latest Prestashop Apache Image
    image: prestashop/prestashop:8.1.1-8.1-fpm  # FPM Nginx Prestashop Image
    restart: unless-stopped
    depends_on:
      - mysql
    environment:
      PS_DEV_MODE: ${PS_DEV_MODE} # Development mode
      PS_INSTALL_AUTO: ${PS_INSTALL_AUTO}  # Install Prestashop automatically
      PS_INSTALL_DB: ${PS_INSTALL_DB}  # Create DB on install
      PS_ERASE_DB: ${PS_ERASE_DB}  # Erase DB on install
      PS_ENABLE_SSL: ${PS_ENABLE_SSL}  # Enable SSL on install
      PS_DOMAIN: ${PS_DOMAIN}  # Domain for Prestashop installation
      DB_SERVER: ${PS_DATABASE_SERVER}  # Project's database server
      DB_NAME: ${PS_DATABASE}  # Project's database
      DB_USER: ${PS_DATABASE_USER}  # Project's database user
      DB_PASSWD: ${PS_DATABASE_PASSWD}  # Project's database password
      ADMIN_MAIL: ${PS_ADMIN_MAIL}  # Prestashop admin email
      ADMIN_PASSWD: ${PS_ADMIN_PASSWD}  # Prestashop admin password
      PS_FOLDER_ADMIN: ${PS_FOLDER_ADMIN}  # Prestashop admin folder/url
    networks:
      - prestashop_network
    volumes:
      - ./src:/var/www/html  # Mount the local src directory to the container

networks:
  prestashop_network:  # Define a shared network for this setup

volumes:
  mysql-data:  # Define the MySQL data volume

nginx.conf:

server {
   server_name localhost;

   location / {
       return 301 https://$host$request_uri;
   }
}

server {
   listen 443 ssl;
   http2 on;
   server_name localhost;

   ssl_protocols TLSv1.2 TLSv1.3;
   ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
   ssl_prefer_server_ciphers off;

   ssl_session_timeout 1d;
   ssl_session_cache shared:MozSSL:10m;
   ssl_session_tickets off;

   ssl_certificate /etc/nginx/ssl/server.crt;
   ssl_certificate_key /etc/nginx/ssl/server.key;

   proxy_connect_timeout 600s;
   proxy_send_timeout 600s;
   proxy_read_timeout 600s;

   location / {
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Host $http_host;
       proxy_set_header X-Forwarded-Proto $scheme;

       proxy_pass http://prestashop;
   }
}
exepowered commented 1 year ago

I just realised my nginx.conf was completely wrong. Now that I fixed it, I can access the Prestashop installer correctly, but the original issue with the 504 Gateway Time-out that I had running the Apache image, occurs with the FPM setup too. I've updated the title of this issue to match my problem correctly.

Everything runs well until Prestashop wants to install the theme. Both Apache and FPM images spits 504 Gateway Time-out error.

Running Docker on M2 Macbook Pro 2023. Ventura 13.4.1

Log:

sklepzherbatamipl-nginx-1  | 172.18.0.1 - - [10/Aug/2023:19:34:22 +0000] "GET /install/index.php?installTheme=true&_=1691695967736 HTTP/2.0" 504 569 "https://localhost/install/index.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "-"
prestashop                 | NOTICE: PHP message: PHP Warning:  require(/var/www/html/var/cache/pro_/ContainerHOomYsF/getConsole_CommandLoaderService.php): Failed to open stream: No such file or directory in /var/www/html/var/cache/pro_/ContainerHOomYsF/appAppKernelProdContainer.php on line 2254
prestashop                 | NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Failed opening required '/var/www/html/var/cache/pro_/ContainerHOomYsF/getConsole_CommandLoaderService.php' (include_path='/var/www/html/vendor/pear/pear_exception:/var/www/html/vendor/pear/console_getopt:/var/www/html/vendor/pear/pear-core-minimal/src:/var/www/html/vendor/pear/archive_tar:.:/usr/local/lib/php') in /var/www/html/var/cache/pro_/ContainerHOomYsF/appAppKernelProdContainer.php:2254
prestashop                 | Stack trace:
prestashop                 | #0 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php(255): ContainerHOomYsF\appAppKernelProdContainer->load('getConsole_Comm...')
prestashop                 | #1 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php(231): Symfony\Component\DependencyInjection\Container->make('console.command...', 1)
prestashop                 | #2 /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(184): Symfony\Component\DependencyInjection\Container->get('console.command...')
prestashop                 | #3 /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(75): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
prestashop                 | #4 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(149): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
prestashop                 | #5 /var/www/html/src/Adapter/Cache/Clearer/SymfonyCacheClearer.php(79): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
prestashop                 | #6 [internal function]: PrestaShop\PrestaShop\Adapter\Cache\Clearer\SymfonyCacheClearer->PrestaShop\PrestaShop\Adapter\Cache\Clearer\{closure}()
prestashop                 | #7 {main}
prestashop                 |   thrown in /var/www/html/var/cache/pro_/ContainerHOomYsF/appAppKernelProdContainer.php on line 2254

Updated nginx.conf for reference:

server {
   server_name localhost;

   location / {
       return 301 https://$host$request_uri;
   }
}

server {
   listen 443 ssl;
   http2 on;
   server_name localhost;

   ssl_protocols TLSv1.2 TLSv1.3;
   ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
   ssl_prefer_server_ciphers off;

   ssl_session_timeout 1d;
   ssl_session_cache shared:MozSSL:10m;
   ssl_session_tickets off;

   ssl_certificate /etc/nginx/ssl/server.crt;
   ssl_certificate_key /etc/nginx/ssl/server.key;

   index index.php index.html;
   root /var/www/html;
   location ~ \.php$ {
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass prestashop:9000;
       fastcgi_index index.php;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param PATH_INFO $fastcgi_path_info;
   }
}
dragonfly4 commented 1 year ago

I got it working after adding this

proxy_read_timeout 600;

exepowered commented 1 year ago

Yup, it worked, but I get error 500 now when using the GUI web installer. 1: HTTP 500 - error - {"success":true,"message":""}

Installing via CGI worked, and I was able to install.