location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://mmt;if ( $remote_addr != 192.168.0.2 ) { access_log /var/log/nginx/nginx_access_abres.log; } }
下面的配置经测试是失败的,依然记录访问日志:
location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://mmt;deny 192.168.0.2; }
推测是日志记录在deny前执行,执行到deny返回403 Forbidden。