这是我的nginx配置文件。nginx部署的server cname是test.com,然后我配置的是如果http访问会跳转到https端口,因为用了load balancer,443的请求会被转发到test.com的90端口。将代码部署到test.com后,本地开发环境会报CORS错误,不知道是哪里配置错误,有人可以帮忙看看吗,谢谢。
Access to XMLHttpRequest at 'http://test.com/api/test/test' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
server {
listen 80;
listen [::]:80;
server_name localhost;
rewrite ^/(.+)$ https://test.com/$1 permanent;
}
server {
listen 90;
listen [::]:90;
server_name localhost;
access_log /var/log/nginx/host.access.log main;
error_page 500 502 503 504 /50x.html;
location / {
rewrite / /angular;
}
location /angular {
add_header Cache-Control no-store;
root /etc/nginx/html;
try_files $uri $uri/ /angular/index.html;
}
location ^~ /api/ {
proxy_pass http://proxy.com:1338;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
rewrite ^/api/(.*) /$1 break;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}
你把nginx配置里面的server_name都改成
test.com