webdevops / php-docker-boilerplate

:stew: PHP Docker Boilerplate for Symfony, Wordpress, Joomla or any other PHP Project (NGINX, Apache HTTPd, PHP-FPM, MySQL, Solr, Elasticsearch, Redis, FTP)
https://webdevops.io/projects/php-docker-boilerplate/
MIT License
562 stars 186 forks source link

fastcgi_params in virtual host of nginx #61

Open mpastas opened 7 years ago

mpastas commented 7 years ago

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;

    }
mblaschke commented 7 years ago

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?

htuscher commented 7 years ago

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

mblaschke commented 7 years ago

@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 commented 7 years ago

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