
比如
location /api { add_header "Access-Control-Allow-Origin: *"; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } 这时,如果访问 api 下的.php ,就没有 add_header 了,只能重新写一个正则匹配,非常不优美。请问有好的解决方案么?
1 AngryPanda 2018-11-15 17:51:18 +08:00 location ~ /api 另外你的 add_header 行写错了。 |
2 1119186082 OP @AngryPanda 谢谢!不过这样写,add_header 有了,但 php 的设置又没有被执行,访问.php 会直接下载源代码#捂脸 |
3 wly19960911 2018-11-15 18:22:12 +08:00 via Android location 可以嵌套 /t/490450 至于能不能起效果你自己试试 |
4 AngryPanda 2018-11-15 18:46:39 +08:00 location ~ [^/]\.php(/|$) { if ($request_uri ~ ^/api/) { add_header Access-Control-Allow-Origin *; } fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } |
5 1119186082 OP @wly19960911 谢谢!我试试 |
6 1119186082 OP @AngryPanda 谢谢啦! |
7 msg7086 2018-11-16 02:52:41 +08:00 这种情况下你可以选择用 include。 |