How do I use the file name of the conf file in the nginx conf file?

If I have a file named mysite.conf stored in /etc/nginx/conf.d. Is there a way to get the string value ‘mysite’ from the conf file?

I want to symlink a common .conf file multiple times because they are all the same except for a small string. As a simple example, instead of this:

server {
#
# snip
#

access_log /var/log/nginx/mysite_access.log;
error_log /var/log/nginx/mysite_error.log;

#
# snip
#
}

I want to do this :

server {
#
# snip
#

access_log /var/log/nginx/$ filename_access.log;
error_log /var/log/nginx/$filename_error.log;

#
# snip
#
}

I want to name the file mysite.conf, I want 5 more symbolic links:

/etc/nginx/conf.d/mynextsite.conf< br />/etc/nginx/conf.d/myothersite.conf
etc

I hope so so that I can reuse the exact same conf file. I thought of this because I You can use the %n variable to use uwsgi. The convenience is that you don’t have to make a bunch of files all the time. I just symlink them to the same place. Can I do it with nginx conf files?

You can use a server block. For example:

< /p>

server {
listen 80;
sever_name example.com example.org domain.net;

error_log /var/log/nginx/${host} _error.log;
access_log /var/log/nginx/${host}_access.log;

....
}

Therefore, The file name is /var/log/nginx/example.org_access.log or /var/log/nginx/domain.net_access.log.

If I have a file named The mysite.conf file is stored in /etc/nginx/conf.d. Is there a way to get the string value’mysite’ from the conf file?

I want to symlink a common .conf file multiple times because they are all the same except for a small string. As a simple example, instead of this:

server {
#
# snip
#

access_log /var/log/nginx/mysite_access.log;
error_log /var/log/nginx/mysite_error.log;

#
# snip
#
}

I want to do this :

server {
#
# snip
#

access_log /var/log/nginx/$ filename_access.log;
error_log /var/log/nginx/$filename_error.log;

#
# snip
#
}

I want to name the file mysite.conf, I want 5 more symbolic links:

/etc/nginx/conf.d/mynextsite.conf< br />/etc/nginx/conf.d/myothersite.conf
etc

I hope so so that I can reuse the exact same conf file. I thought of this because I You can use the %n variable to use uwsgi. The convenience is that you don’t have to make a bunch of files all the time. I just symlink them to the same place. Can I do it with nginx conf files?

You can use a server block. For example:

server {
listen 80;
sever_name example.com example.org domain.net;

error_log /var/log/nginx/${host}_error.log;
access_log /var/ log/nginx/${host}_access.log;

....
}

Therefore, the file name is /var/log/nginx/example. org_access.log or /var/log/nginx/domain.net_access.log.

Leave a Comment

Your email address will not be published.