JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

has been blocked by CORS policy_nginx解决跨域问题

wys521 2024-09-11 13:24:53 精选教程 25 ℃ 0 评论

关于跨域的问题,是老生常谈了....这回又出现了...


?


不过这个跨域问题是可以在nginx中配置解决了:


直接看nginx.conf配置文件把:


下面的:


charset utf-8;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers Origin,X-Requested-Width,Content-Type,Accept;


这一部分就是用来解决跨域的


    server {
        listen       8001;
        server_name  localhost;

charset utf-8;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers Origin,X-Requested-Width,Content-Type,Accept;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

 location / {
	 root  D:/ALLSVN/ydy/YdyFront;
        	 index  userLogin.html userLogin.htm;
        }

 location /api {
	 proxy_pass http://172.19.128.53:8080/api;
        }

      location /login {
	 proxy_pass http://172.19.128.53:8080/login;
        }

	location /videoUrl {
	 proxy_pass http://cctvalih5ca.v.myalicdn.com/live/cctv1_2;
      	  }
	location /img{
		rewrite ^/img/(.*)$ /$1 break;
		root D:/resource/upload/img;
	}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }





?

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表