nginx设置如下,客户端直接访问本地服务器83端口,通过http://localhost:83/wmaps/xml/baoding.xml实现对国家气象局天气实况的实时访问。
nginx.conf设置如下:
server{ listen 83; server_name 192.168.1.1; location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; if ($request_method = 'OPTIONS') { return 204; } proxy_pass http://flash.weather.com.cn; } }
此处注意
if ($request_method = ‘OPTIONS’) {
必须有,不然浏览器还是会报跨域错误。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)