简体   繁体   English

Nginx:在指定访问日志位置时我可以使用$ server_name吗?

[英]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_logerror_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.

相关问题 根据server_name更改NGINX根目录位置 - Change NGINX root location depending on server_name 带有多个“server_name”条目的nginx“server”指令:始终将第一个传递给PHP的$ _SERVER ['SERVER_NAME'] - nginx “server” directive with multiple “server_name” entries: always first one is passed to PHP's $_SERVER['SERVER_NAME'] 在 nginx 配置服务器名称中使用通配符 - use wildcard in nginx configuration server name 在服务器启动时更改jboss-log4j.xml的名称/位置 - Changing name/location of jboss-log4j.xml on server startup 如何在不指定 Unix 中所有 C 编译器的位置的情况下为程序配置指定一个文件的位置? - How can I specify the location of one file for program configuration without specifying the location for all C compilers in Unix? NGINX access.log 未更新 - NGINX access.log not updating 如何编写与url /%ef匹配的nginx位置指令? - How can I write an nginx location directive that matches the url /%ef? 我可以让Nginx以不同的方式记录某些类型的请求吗? - Can I get Nginx to log certain types of requests differently? 如何在nginx中重用服务器配置? - How can I reuse server configurations in nginx? 为什么不能上传大文件到nginx服务器? - Why can't I upload a big file to nginx server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM