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里面根据url的规则,做了下rewrite操作
现在想增加一个web站点的location, 如下

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

通常情况下,如果没有上面的rewrite的location, 根loation /会指向下面的这个html页面
但是我本以为这个/admin的location会生效。 毕竟location是遵循惰性加载的。实际上并没有生效。
不知道为啥?

阅读 4k
2 个回答

location = ~^/admin 是什么语法?要么精确匹配,要么正则匹配,哪有一起用的?我猜你应该是想用 location /admin

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

深夜写location, 很容易出错。正确的是这样的

location /admin {
    root   html;
    index  index.html index.htm;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题