欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

nginx支持跨域访问

程序员文章站 2022-06-30 22:13:59
1,进入nginx的html目录 vim ./crossdomain.xml 具体路径: /usr/local/nginx/html/crossdomain.xml 2,在crossdomain.xml中添加: 1 2 3 4 5 6 结果就是: 注意:默认/usr/local/nginx/html ......

1,进入nginx的html目录 
vim ./crossdomain.xml 
具体路径: /usr/local/nginx/html/crossdomain.xml 
2,在crossdomain.xml中添加:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果就是: 
nginx支持跨域访问

注意:默认/usr/local/nginx/html/crossdomain.xml 是不存在的.

nginx做请求转发

修改:/usr/local/etc/nginx/vhosts/xx.com.conf

server {
        listen 80;
        server_name xxx.com  10.1.146.81;

        location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' '*';
        proxy_pass http://localhost:8088;
        # proxy_redirect off ;

        index index.php index.html index.htm;
        }
# error_page 500 502 503 504 /50x.html;


}