prevent nginx Docker container from exit

6/13/2018

I have an nginx container and a php-fpm one. I use K8S and both containers are in the same pod. I want to configure nginx timeout or something similar to wait for the upstream.

This is my config:

server {
server_name mywebserver;
root /myapp;

location / {
    try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
    resolver 127.0.0.1 valid=30s;
    fastcgi_pass myapp:9000;
    proxy_connect_timeout 120;
    proxy_read_timeout 120;

    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;



    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    internal;
}

location ~ \.php$ {
    return 404;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;

}

I added:

proxy_connect_timeout 120;
proxy_read_timeout 120;

but it seems that it's not working. Is there any reliable solution for this ?

-- 4m1nh4j1
devops
docker
kubernetes
nginx

1 Answer

6/13/2018
resolver 127.0.0.1 valid=30s;
fastcgi_pass myapp:9000;

Hardly makes any sense, just go for 127.0.0.1, unless you want to loadbalance between myapp backends, in which case, it is counterintuitive to keep them in the same pod, you should then use a php-fpm as separate backend deployment and service

-- Radek 'Goblin' Pieczonka
Source: StackOverflow