How does nginx reuse partial configuration blocks?

for example, the following configuration block. I have N PHP sites, and they all have the same configuration items except server_name and root. Is there any way to reuse the same configuration?

by the way, is there a security risk to my next configuration item? If so, how do I modify it?

Thank you very much! ^ _ ^

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    root /var/www/html;
    
    -sharp Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;
    
    server_name www.xxx.com;
    
    location / {
            -sharp First attempt to serve request as file, then
            -sharp as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }       
    
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }       
    
    location ~ /\.ht {
        deny all;
    }
}

Nov.05,2021

generally reuse just use include statement, there is no good method for the time being.
(when you finish writing the Caddy configuration and then come back to see the Nginx configuration, you will feel like cursing the street. )

Menu