我创build了一个WordPress页面,用于WordPress的健康状况监测,链接为http://domain.tld/health_status 。 它经常被访问,所以我不希望这些请求出现在我的访问日志中。
所有WordPress页面的基本“重写规则”是:
location / { try_files $uri $uri/ /index.php?q=$args; }
现在,在同一层面上,我尝试了
location /health_status { access_log off; #try_files $uri $uri/ /index.php?q=$args; }
从nginx 位置文档 :
文字string匹配查询的开始部分 – 将使用最具体的匹配
/health_status比/更具体,所以当我请求http://domain.tld/health_status时,这个块会采取行动。
在try_files行注释(如上),请求不会显示在访问日志,万岁,但显然我只是得到一个404错误,因为nginx不redirect到WordPress的这个请求。
在try_files行处于活动状态时,会发生内部redirect到WordPress的index.php ,并在浏览器中显示/health_status WordPress页面。 但是,在内部redirect之后, location /health_status块不再location /health_status ,并且请求在访问日志中结束。
如何干净地解决这个问题? 现在是否必须添加另一个与实际的/index.php?q=healthstatuswhatever匹配的块,而/index.php?q=healthstatuswhatever内部redirect之后发生/index.php?q=healthstatuswhatever请求?
谢谢!
你应该使用一个命名的位置来发送到WordPress的请求。 这方面的一个例子:
location ~ \.php$ { try_files $uri =404; fastcgi_ ### fastcgi params and other config for PHP go here } location @wordpress { try_files $uri /index.php; fastcgi_ ### fastcgi params and other config for WP go here } location / { try_files $uri $uri/ @wordpress; } location /health_status { access_log off; try_files $uri $uri/ @wordpress; }
这个例子是不完整的,可能是不安全的; 它只是演示如何解决您的问题。 务必妥善保护您的networking服务器。