php-docker-boilerplate icon indicating copy to clipboard operation
php-docker-boilerplate copied to clipboard

fastcgi_params in virtual host of nginx

Open mpastas opened this issue 8 years ago • 4 comments

Hi guys!

I'm wondering if it is possible to set fastcgi_param in virtual hosts. Currently the only file that make any change in the environment variables is the default one /etc/nginx/fastcgi_params

What I'm trying:

    location ~ \.php$ {

        fastcgi_param TESTVAR  testvar;

    }

mpastas avatar May 13 '17 02:05 mpastas

Just upload your own configuration file to /opt/docker/etc/nginx/vhost.common.d/10-php.conf (source eg. https://github.com/webdevops/Dockerfile/blob/develop/docker/php-nginx/debian-7/conf/etc/nginx/vhost.common.d/10-php.conf)

ENV vars are not enough?

mblaschke avatar May 14 '17 15:05 mblaschke

Or if you dynamically want to modify the config, you could do also use the new service bootstrapping in combination with go-replace to dynamically add some things to config files.

See https://gist.github.com/hhoechtl/78bce01aefc4a65c1ffd337872f3f01f

htuscher avatar May 14 '17 16:05 htuscher

@hhoechtl you can also use (with go-replace 1.1.x):

go-replace --mode=lineinfile --lineinfile-before='}' --regex \
    -s 'fastcgi_param TESTVAR' 
    -r 'fastcgi_param TESTVAR  testvar;' 
    -- /opt/docker/etc/nginx/vhost.common.d/10-php.conf

Which will replaces the line fastcgi_param TESTVAR (if found) or add a new line just before the closing }

Result will be:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME     $request_filename;
    fastcgi_read_timeout 1000;
fastcgi_param TESTVAR  testvar;
}

mblaschke avatar May 14 '17 17:05 mblaschke

go-replace 1.1.x is available with newest images :)

mblaschke avatar May 18 '17 21:05 mblaschke