Using variable in vhost

Karl Johnson karljohnson.it at gmail.com
Tue Jun 12 19:48:19 UTC 2018


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 at 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 at 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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20180612/28a197ba/attachment.html>


More information about the nginx mailing list