【问题标题】:nginx proxy config not forwarding requests to backend servernginx 代理配置未将请求转发到后端服务器
【发布时间】:2016-03-29 00:10:21
【问题描述】:

下面是我的 nginx.conf 文件的相关部分。 当我删除 conf 文件中的初始位置块时,我只看到 js|css... 请求转发到我的后端服务器。我试图完成的是关闭这些扩展文件的 nginx 访问日志记录。

有人知道一种有效的 nginx 配置技术,可以让我关闭访问日志,但仍将这些请求转发到代理位置?

...   
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            access_log   off;
}

location / {

if ($ignore_ua) {
    access_log off;
    return 200;
}
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:7777/;
}

【问题讨论】:

    标签: nginx


    【解决方案1】:

    nginx 选择一个位置块来处理请求。对于.js 文件,使用您的location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ 块。不涉及location / 块中的任何指令。详情请见this document

    如果您需要条件日志记录,您可以在access_log 指令中使用if= 参数,而不是单独的位置块。示例见this document

    在你的情况下,它可能看起来像这样:

    map $request_uri $loggable {
        default 1;
        \.(js|css|png|jpg|jpeg|gif|ico)(\?|$) 0;
    }
    access_log /path/to/access.log combined if=$loggable;
    

    请注意,map 指令位于 http 块中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 2023-04-02
      • 2022-06-16
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2016-04-10
      相关资源
      最近更新 更多