2.nginx
配置
# 至少需要一个 Hyperf 节点,多个配置多行
upstream a2admin {
# Hyperf HTTP Server 的 IP 及 端口
server 127.0.0.1:9611;
}
server
{
listen 80;
server_name xxxxx;
..........
location /{
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,PATCH,OPTIONS;
# 解决假请求问题,如果是简单请求则没有这个问题,但这里是上传文件,首次请求为 OPTIONS 方式,实际请求为 POST 方式
# Provisional headers are shown.
# Request header field Cache-Control is not allowed by Access-Control-Allow-Headers in preflight response.
add_header Access-Control-Allow-Headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization';
return 200;
}
........
proxy_pass http://a2admin;
}
}