Welcome! Log In Create A New Profile

Advanced

Using variable in vhost

Karl Johnson
June 12, 2018 03:50PM
Hello,

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.

Thanks,
Karl

[root@web ~]# 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;
}



[root@web ~]# 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
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Using variable in vhost

Karl Johnson June 12, 2018 03:50PM

Re: Using variable in vhost

huguesjoyal October 04, 2018 03:16PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 284
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready