Nginx 位置 try_files 与 add_header 重定向和 cors

2024-03-23

我想将请求重定向到index.php以启用漂亮的链接,使用try_files可以实现此目的,但是我似乎无法让try_files和add_headers同时工作

我当前的位置块如下所示:

location /api/v1/ {

        try_files $uri /sephaku/api/v1/index.php?$query_string;
        add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken';
        add_header 'Access-Control-Allow-Origin' 'http://0.0.0.0:9000';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Headers' 'Authorization';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';


    }

但标题似乎没有添加。

我尝试添加一个 if 语句,如下所示:

if ($request_method = 'GET') { }

我的标题在里面。在这种情况下,标头起作用,但重定向不起作用。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Nginx 位置 try_files 与 add_header 重定向和 cors 的相关文章

随机推荐