nginx:No ‘Access-Control-Allow-Origin‘ header is present on the requested resource

nginx:No ‘Access-Control-Allow-Origin’ header is present on the requested resource

需要在nginx的配置文件中某类请求下添加跨域的数据
(1)比如:静态文件:

我这边请求静态文件的时候,直接进入static,之后通过绝对路径找对应的资源,则在/static下面加跨域的数据
server {
	listen	8003;
	server_name	192.168.xxx.xxx;
	
	location /static {
		add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Methods *;
		add_header Access-Control-Allow-Headers *;
		root 	E:/GoTionBackends/RenZhiZhangAi;
	}
	
	location / {
		index  index.html index.htm;
		proxy_pass http://192.168.xxx.xxx:8081;
	}
}

(2) 请求

感觉一般情况下,请求是不会出现跨域的,因为我们后端都会处理
server {
	listen	8003;
	server_name	192.168.xxx.xxx;
	
	location /static {
		root 	E:/GoTionBackends/RenZhiZhangAi;
	}
	
	location / {
		add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Methods *;
		add_header Access-Control-Allow-Headers *;
		index  index.html index.htm;
		proxy_pass http://192.168.xxx.xxx:8081;
	}
}

你可能感兴趣的:(Java,nginx,nginx,java)