1、配置跨域
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "*";
add_header Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
try_files $uri $uri/ /index.php?$args;
}
2、配置隐藏index.php
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
本文介绍了如何使用Nginx配置跨域请求,通过设置Access-Control-Allow-*头实现允许所有来源的跨域请求,并处理预检请求。同时,也展示了隐藏index.php的配置方法,通过rewrite规则实现URL美化,确保请求正确路由到PHP处理器。
2455

被折叠的 条评论
为什么被折叠?



