我想禁用某些特定路徑的訪問日志記錄,但仍將其代理到另一個容器。換句話說,“在不回傳/退出的情況下匹配多個位置”據我所知這是不可能的。
以下配置將使 nginx 在不輸入代理傳遞位置的情況下取消請求。
server {
# ...
# do not log requests for /_nuxt/* and /_ipx/*
location ~ ^/(_ipx|_nuxt) {
access_log off;
}
# still proxy these paths
location ~* ^(\/|\/(foo|bar|_nuxt|_ipx)$ {
proxy_pass http://frontend:3000;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $server_name:$server_port;
}
}
除了復制代理配置并將訪問日志配置行添加到第二個位置之外,是否有更簡潔的方法來實作所需的行為?
server {
# ...
# proxy pass without _nuxt and _ipx
location ~* ^(\/|\/(foo|bar)$ {
proxy_pass http://frontend:3000;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $server_name:$server_port;
}
# access log proxy pass
location ~ ^/(_ipx|_nuxt) {
access_log off;
proxy_pass http://frontend:3000;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $server_name:$server_port;
}
}
uj5u.com熱心網友回復:
你是對的,location就像開關盒一樣,首先受到打擊和破壞。也許你可以嘗試這樣的事情:
if ($request_uri ~ ^/(_ipx|_nuxt)) {
access_log off;
}
而不是您的第一個位置宣告。
uj5u.com熱心網友回復:
更新:以下解決方案不可行。
我把它作為對所有人的警告。雖然相同的方法適用于其他一些指令(例如auth_basic,作業示例),但不適用于access_log指令。
@araisch 提出的解決方案應該可以作業,只是為了完整起見,還有一個選項可以使用該map塊執行相同的操作:
map $uri $logfile {
~^/_(ips|nuxt) off;
default /path/to/access.log;
}
server {
...
access_log $logfile; # or 'access_log $logfile <format>'
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415691.html
標籤:
上一篇:誰來設計和實作FRONTEND(nginx&react)和BACKEND(laravel&mongo)的容器化架構
