[英]Nginx: can I use $server_name when specifying access log location?
I want to write a config file for an nginx virtual host that looks like this: 我想为nginx虚拟主机编写一个配置文件,如下所示:
server {
listen 80;
server_name www.my-domain-name.com;
access_log /home/me/sites/$server_name/logs/access.log;
error_log /home/me/sites/$server_name/logs/error.log;
location /static {
alias /home/me/sites/$server_name/static;
}
location / {
proxy_pass http://localhost:8000;
}
}
Using $server_name
seems to work find for the location /static
, but it doesn't seem to work for the access_log
and error_log
-- am I doing something wrong? 使用
$server_name
似乎找不到location /static
,但它似乎不适用于access_log
和error_log
- 我做错了什么? Or is this just not possible? 或者这是不可能的? Can I do it some other way?
我可以用其他方式吗?
[update] - this is the error message when trying to reload nginx: [更新] - 这是尝试重新加载nginx时的错误消息:
nginx: [emerg] open() "/home/me/sites/$server_name/logs/error.log" failed (2: No such file or directory)
I wanted to do this too, but apparently by design nginx cannot expand variables in the error_log
command, in case there are errors doing so and it cannot get a log filename to write them to. 我也想这样做,但显然通过设计nginx无法在
error_log
命令中扩展变量,以防有错误这样做并且它无法获取日志文件名来写入它们。
Their suggestion is to use some program to generate your configuration files instead. 他们的建议是使用某些程序来生成配置文件。 You could use
sed
for this, to automatically search-and-replace your own variables and placing the output in the nginx configuration directory. 您可以使用
sed
来自动搜索和替换您自己的变量并将输出放在nginx配置目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.