nginx.测试用于处理请求的位置 [英] nginx. Test which location used to process request

查看:79
本文介绍了nginx.测试用于处理请求的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何知道某个特定位置是否用于处理nginx中的请求.

I'm wondering how do I know if a particular location[s] used to process request in nginx.

例如:

# 1
location / {}

# 2
location ~ /[\w\-]+\.html {}

# 3
location ~ /\w+\.html {}

我怎么知道像/mysite这样的URI是否由第3个位置而不是第2个位置处理? 对于此问题,我倾向于使用 add_header :

How do I know if URI like /mysite is processed by 3rd location and not 2nd? I tend to use add_header for this matter:

location / {
    add_header location 1;
}

location ~ /(\w+\-)\.html {
    add_header location 2;    
}

location @named {
    add_header location named;
}

我想知道是否有更好的解决方案,或者您个人将其用于调试目的?

And I'd like to know is there a better solution or what do you personally use for debugging purposes?

推荐答案

add_header技巧就是我要这样做的方式.

The add_header trick is how I would do it to.

我现在正在工作,所以我无法测试,但是如果您将error_log级别设置为:

I'm at work right now, so I can't test but you might possibly get something in the logfile i you set the error_log level to:

  • debug:您需要使用--with-debug构建nginx才能正常工作,您可以使用nginx -V命令检查
  • notice:如果未启用调试日志记录
  • debug: you're nginx needs to be built using --with-debug for this to work, you can check that with the nginx -V command
  • notice: if debug logging isn't enabled

这篇关于nginx.测试用于处理请求的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆