鍍金池/ 問答/Linux  網(wǎng)絡安全/ openresty的location配置問題rewrite_by_lua引起的一

openresty的location配置問題rewrite_by_lua引起的一個問題

nginx.conf里面的有一個配置是這樣的

    location / {
        default_type 'application/json;charset=utf-8';
        # here must be use rewrite_by_lua instead of content_by_lua
        rewrite_by_lua '
            #  一些url的處理
        '
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.1.101:8012/;
    }
    

其中,rewrite_by_lua里面根據(jù)url的規(guī)則,做了下rewrite操作
現(xiàn)在想增加一個web站點的location, 如下

    location = ~^/admin {
        root   html;
        index  index.html index.htm;
    }
    

通常情況下,如果沒有上面的rewrite的location, 根loation /會指向下面的這個html頁面
但是我本以為這個/admin的location會生效。 畢竟location是遵循惰性加載的。實際上并沒有生效。
不知道為啥?

回答
編輯回答
陌如玉

location = ~^/admin 是什么語法?要么精確匹配,要么正則匹配,哪有一起用的?我猜你應該是想用 location /admin。

文檔: https://nginx.org/en/docs/htt...

2018年3月15日 10:01
編輯回答
不將就

深夜寫location, 很容易出錯。正確的是這樣的

location /admin {
    root   html;
    index  index.html index.htm;
}
2018年8月17日 09:27