evertramos / nginx-proxy-automation

Automated docker nginx proxy integrated with letsencrypt.
MIT License
2.66k stars 632 forks source link

504 Gateway timeout #348

Closed cod3rshotout closed 2 years ago

cod3rshotout commented 2 years ago

Hi,

I'm trying to run a really long script over nginx-proxy-automation, after 60s I get from nginx this error:

504 Gateway timeout

I tried to fix this increasing the timeout value in the proxy-web-auto container, so I have created a new file within the conf.d folder called timeout.conf with the following content:

[proxy_read_timeout 600s;
fastcgi_read_timeout 600s;

In this way the script should run for 10 minutes max.

Then I executed this command: docker-compose down -v and docker-compose up --build and tested again the script, but again, after a minute the same nginx error.

The app, run over php-fpm and nginx and I have two container:

version: '3.9'

services:

  bcm-fpm:
    container_name: bcm_app
    restart: always
    build:
      context: .
      dockerfile: ./docker/php-fpm/Dockerfile
    volumes:
      - ./src:/var/www/html
      - ./docker/php-fpm/config/www.conf:/usr/local/etc/php-fpm.d/www.conf
      - ./src/public:/bcm_app/public

  nginx:
    image: nginx:stable-alpine
    container_name: bcm_nginx
    restart: always
    volumes:
      - ./src:/var/www/html
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/sites/:/etc/nginx/sites-available
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d
    depends_on:
      - bcm-fpm
    environment:
      VIRTUAL_HOST: ${HOST}
      LETSENCRYPT_HOST: ${HOST}
      LETSENCRYPT_EMAIL: ${EMAIL}

This the nginx configuration:

docker/nginx/conf.d/default.conf

upstream php-upstream {
    server bcm-fpm:9000;
}

docker/nginx/site/default.conf

server {
    root   /var/www/html;
    index index.php;

    add_header Access-Control-Allow-Origin *;

    location / {
        add_header Access-Control-Allow-Origin *;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ [^/]\.php(/|$) {
        add_header Access-Control-Allow-Origin *;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_pass   php-upstream;
        fastcgi_index  index.php;
    }
}

docker/nginx/nginx.conf

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    client_max_body_size 100M;

    access_log  /var/log/nginx/access.log;
    # Switch logging to console out to view via Docker
    #access_log /dev/stdout;
    #error_log /dev/stderr;

    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-available/*.conf;
}

How can I fix this problem?

evertramos commented 2 years ago

I don´t think this is a bug, but a question.

You must have the configuration loaded in nginx ontianer. Did you check if it was loaded as expected?

Where did you place your timeout.conf? Which folder?

Check this as well:

https://github.com/evertramos/nginx-proxy-automation/issues/220

cod3rshotout commented 2 years ago

I don´t think this is a bug, but a question.

You must have the configuration loaded in nginx ontianer. Did you check if it was loaded as expected?

Where did you place your timeout.conf? Which folder?

Check this as well:

220

Hi, thanks for the quick reply and sorry for the bug label.

The folder is this: https://github.com/evertramos/nginx-proxy-automation/tree/master/conf.d and the file timeout.conf should be automatically added to the nginx configuration.

I'm checking the resources you gave to me, but I hope to a further help on your side

evertramos commented 2 years ago

@cod3rshotout the folder conf.d is only copied once when you use fresh-start.sh script with option --use-nginx-conf-files.

Other wise you must check your .env to see where the nginx files are and add this file there, so the nginx can read them from inside the container.

After you do that you must reload the nginx and check if your settings are there.

cod3rshotout commented 2 years ago

@cod3rshotout the folder conf.d is only copied once when you use fresh-start.sh script with option --use-nginx-conf-files.

Other wise you must check your .env to see where the nginx files are and add this file there, so the nginx can read them from inside the container.

Yep, when I've installed the proxy I used the --use-nginx-conf-files flag, so the file should be available in the nginx configuration.

Forgot to say that when I use nginx -s reload I get:

"keepalive_timeout" directive is duplicate in /etc/nginx/conf.d/timeout.conf:6 nginx: [emerg] "keepalive_timeout" directive is duplicate in /etc/nginx/conf.d/timeout.conf:6

this is the content of timeout.conf:

fastcgi_read_timeout        600s;
proxy_connect_timeout       600s;
proxy_send_timeout          600s;
proxy_read_timeout          600s;
send_timeout                600s;
keepalive_timeout           600s;
cod3rshotout commented 2 years ago

I was able to fix it, the issue isn't related to the nginx-proxy-automation container but on the app container, to fix it I've added this on the location block:

    fastcgi_read_timeout 60000;

so it would be:

location ~ [^/]\.php(/|$) {
    add_header Access-Control-Allow-Origin *;
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;

    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

    fastcgi_pass   php-upstream;
    fastcgi_index  index.php;

    fastcgi_read_timeout 60000;
}