域名绑定识别返回固定串之nginx的Location正则匹配的生效问题

今天测试个nginx问题

需要匹配 /*.txt类型,然后返回个固定串。

开始写法如下:

        location  ~ ^/*.txt {
                default_type text/html;
                return 200 'asdhfqwuehrdjfsafj';
        }

测试发现正则不生效,于是尝试了下面两种写法好使

location  ~* \.(txt)$ {
                default_type text/html;
                return 200 'asdhfqwuehrdjfsafj';
        }

location ~ ^/.*\.txt$ {
                default_type text/html;
                return 200 'asdhfqwuehrdjfsafj';
        }

 

        location = /lalala.txt {
                default_type text/html;
                return 200 'asdhfqwuehrdjfsafj';
        }

 

posted @ 2020-04-28 19:38  xuzhujack  阅读(360)  评论(0编辑  收藏  举报
;