Quantcast
Channel: Nginx Forum - Nginx Mailing List - Russian
Viewing all articles
Browse latest Browse all 3102

В каком порядке обрабатываются location? (4 replies)

$
0
0
Доброе время суток!
Слегка запутался в порядке обработки локейшенов.
Такая структура:

/1/index.html
/23/index.html
/456/index.html
/7890/index.html

Все файлы index.html, естественно, разные.

Соответственно, тестовый конфиг:

server {
    ....
    location = /1/ { rewrite ^ /1/index.html break; }
    location = /23/ { rewrite ^ /23/index.html break; }
    location = /456/ { rewrite ^ /456/index.html break; }
    location = /7890/ { rewrite ^ /7890/index.html break; }

    location ~ (\.html$|\.php$) { internal; }

    location "" { return 404; }

    error_page 404 = @err404;

    # все, что не соответствует
    location @err404 {
        keepalive_timeout 0;
        rewrite ^ /err/404.html break;
    }
}

Из дебага:

2018/02/12 16:02:05 [debug] 11200#11200: *1 http request line: "GET /1/ HTTP/1.1"
2018/02/12 16:02:05 [debug] 11200#11200: *1 http uri: "/1/"

2018/02/12 16:02:05 [debug] 11200#11200: *1 test location: ""
<<< === здесь ожидалось test location: "/7890/", как локейшен максимальной длины
2018/02/12 16:02:05 [debug] 11200#11200: *1 test location: "/456/"
2018/02/12 16:02:05 [debug] 11200#11200: *1 test location: "/23/"
2018/02/12 16:02:05 [debug] 11200#11200: *1 test location: "/1/"
2018/02/12 16:02:05 [debug] 11200#11200: *1 using configuration "=/1/"

=====================================================

2018/02/12 16:03:05 [debug] 11246#11246: *1 http request line: "GET /23/ HTTP/1.1"
2018/02/12 16:03:05 [debug] 11246#11246: *1 http uri: "/23/"

2018/02/12 16:03:05 [debug] 11246#11246: *1 test location: ""
<<< === здесь также ожидалось test location: "/7890/", как локейшен максимальной длины
2018/02/12 16:03:05 [debug] 11246#11246: *1 test location: "/456/"
2018/02/12 16:03:05 [debug] 11246#11246: *1 test location: "/23/"
2018/02/12 16:03:05 [debug] 11246#11246: *1 using configuration "=/23/"

=======================================================

2018/02/12 16:03:51 [debug] 11283#11283: *1 http request line: "GET /456/ HTTP/1.1"
2018/02/12 16:03:51 [debug] 11283#11283: *1 http uri: "/456/"

2018/02/12 16:03:51 [debug] 11283#11283: *1 test location: ""
2018/02/12 16:03:51 [debug] 11283#11283: *1 test location: "/456/"
2018/02/12 16:03:51 [debug] 11283#11283: *1 using configuration "=/456/"

=====================================================
Запрос в несуществующий локейшен

2018/02/12 16:22:47 [debug] 11285#11285: *3 http request line: "GET /7890/qqqqqqqqqqqq HTTP/1.1"
2018/02/12 16:22:47 [debug] 11285#11285: *3 http uri: "/7890/qqqqqqqqqqqq"

2018/02/12 16:22:47 [debug] 11285#11285: *3 test location: ""
2018/02/12 16:22:47 [debug] 11285#11285: *3 test location: "/456/"
2018/02/12 16:22:47 [debug] 11285#11285: *3 test location: "/7890/"
2018/02/12 16:22:47 [debug] 11285#11285: *3 test location: ~ "(\.html$|\.php$)"
2018/02/12 16:22:47 [debug] 11285#11285: *3 using configuration ""

2018/02/12 16:22:47 [debug] 11285#11285: *3 rewrite phase: 3
2018/02/12 16:22:47 [debug] 11285#11285: *3 http finalize request: 404, "/7890/qqqqqqqqqqqq?" a:1, c:1
2018/02/12 16:22:47 [debug] 11285#11285: *3 http special response: 404, "/7890/qqqqqqqqqqqq?"
2018/02/12 16:22:47 [debug] 11285#11285: *3 test location: "@err404"
2018/02/12 16:22:47 [debug] 11285#11285: *3 using location: @err404 "/7890/qqqqqqqqqqqq?"
......
=====================================================

Т.е. работает-то оно правильно, но проверки существующих локейшенов почему-то всегда начинаюся с "/456/". Не понимаю, чем он такой особенный? Если отталкиваться от длины, так самый длинный "/7890/"

Спасибо.

--_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru

Viewing all articles
Browse latest Browse all 3102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>