我正在尝试使用单个服务器部署Web应用程序。
这是我当前的nginx配置(在尝试了几个小时后):
server {
listen 80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
add_header Strict-Transport-Security "max-age=31536000";
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
add_header Access-Control-Allow-Origin *;
location / {
root /var/www/client;
}
location /cdn/ {
proxy_pass https://s3.eu-central-1.amazonaws.com/some_bucket;
}
}
server {
listen 433 ssl;
server_name api0.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Request-Method' '*';
add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET';
add_header 'Access-Control-Allow-Headers' '*';
location / {
proxy_pass http://127.0.0.1:8082/;
}
}
我的静态网站正在向api0发出Socket.io请求。这失败了,Chrome说:
XMLHttpRequest无法加载https://api0.example.com/socket.io/?EIO=3&transport=polling&t=1483705935443-97。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' https://www.example.com'因此不允许访问。响应的HTTP状态代码为404.
我做错了什么?