Welcome! Log In Create A New Profile

Advanced

Multiple domains templating

Posted by SirLouen 
Multiple domains templating
December 30, 2024 12:11PM
Hello

Coming from Caddy there is a feature where I can include a file passing arguments to the file, hence designing template files is very neat and straigthforward

Imagine I have 100 domains, domain1.com, domain2.com, ... domain100.com

And I want to use NGINX as a reverse proxy for such domains
How can I create a simple config, to pass the minimum text I can configure them all significantly? (including logging, expires, compression, and all the features I want)?

So far the only idea I've found is passing $server_name to all configurable parameters except for server_name and error_log and have in one file all like:

server {
include /path_to_templated elements that accept $server_name
server_name domain1.com
error_log /var/log/nginx/error-domain1.com.log;
}

server {
include /path_to_templated elements that accept $server_name
server_name domain2.com
error_log /var/log/nginx/error-domain2.com.log;
}

...

server {
include /path_to_templated elements that accept $server_name
server_name domain100.com
error_log /var/log/nginx/error-domain100.com.log;
}

From what I've read, server_name and error_log are some of the few directives that don't admit variables, hence templating like this is impossible (the only templating I've seen is designed for separate instances of Nginx passing ENV variables which I don't find too useful in this scenario because I cannot conditionally control them inside Nginx

Anyway its not terrible this way, but since I'm an Nginx newcomer I was simply wondering if there is something better than this.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 114
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready