Welcome! Log In Create A New Profile


Using variable in vhost

Posted by Karl Johnson 
Karl Johnson
Using variable in vhost
June 12, 2018 09:50PM

I have a nginx multi-user setup that use the same fpm config for all vhost
but each vhost has his own user so I had to set a variable in the vhost
config to set the fastcgi_pass path in the included file. This way the
vhost config is always clean.

I've read somewhere that variable in vhost is not recommended. What do you
think of this setup? It's currently working pretty well so I was wondering.


[[email protected] ~]# cat /etc/nginx/conf.d/vhosts/exemple.com.conf
server {
listen 80;
server_name exemple.com;
root /home/webtest/exemple.com/public_html;
access_log /var/log/nginx/exemple.com-access_log main;
error_log /var/log/nginx/exemple.com-error_log warn;

set $fpmuser webtest;

if ($bad_bot) { return 444; }

include conf.d/custom/restrictions.conf;
include conf.d/custom/pagespeed.conf;
include conf.d/custom/fpm-wordpress-user.conf;

[[email protected] ~]# cat /etc/nginx/conf.d/custom/fpm-wordpress-user.conf
location / {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
try_files $uri $uri/ /index.php?$args;

location ~*
\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ {
expires 2w;
log_not_found off;

location ~* \.(?:css|js)$ {
expires 1w;
add_header Pragma public;
add_header Cache-Control "public";

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 256k;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/$fpmuser.sock;
nginx mailing list
Sorry, only registered users may post in this forum.

Click here to login