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

504 Gateway timeout #348

Closed
cod3rshotout opened this issue Feb 25, 2022 · 5 comments
Closed

504 Gateway timeout #348

cod3rshotout opened this issue Feb 25, 2022 · 5 comments
Assignees
Labels

Comments

@cod3rshotout
Copy link

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
Copy link
Owner

evertramos commented Feb 25, 2022

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

@evertramos evertramos changed the title [BUG] 504 Gateway timeout 504 Gateway timeout Feb 25, 2022
@cod3rshotout
Copy link
Author

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
Copy link
Owner

evertramos commented Feb 25, 2022

@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
Copy link
Author

cod3rshotout commented Feb 25, 2022

@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
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants