Nuxt.js无法从不同端口的Express后端加载数据问题排查
问题:CORS错误还是SSL证书问题?
我的NUXT SSR网站https://tejasjadhav2001.tech部署在https://34.93.29.137:3333,REST后端的Express.js服务器部署在https://34.93.29.137:3000。https://34.93.29.137:3333通过Nginx代理到根域名tejasjadhav2001.tech。
前端API调用代码
getArticles(id) { return axios({ method: "GET", url: `https://34.93.29.137:3000/api/v1/blog/`, withCredentials: true, });
后端CORS配置
尽管已在后端配置CORS,但请求后端时仍出现CORS错误:
const corsOptions ={ origin:[ 'https://34.93.29.137:3000/', 'https://34.93.29.137:3333', 'https://34.93.29.137', 'https://tejasjadhav2001.tech', 'http://tejasjadhav2001.tech', ], credentials:true, //access-control-allow-credentials:true optionSuccessStatus:200 } console.log("Using cors options"); app.use(cors(corsOptions));
特殊现象
手动通过浏览器调用后端API(如https://34.93.29.137:3000/api/v1/blog),接受SSL警告后加载数据,此时再访问https://34.93.29.137:3333或https://tejasjadhav2001.tech,网站能正常加载后端数据。
Nginx配置
a@instance-1:~$ cat /etc/nginx/sites-available/default server { listen 443 ssl; server_name tejasjadhav2001.tech www.tejasjadhav2001.tech; gzip on; gzip_types text/plain application/xml; gzip_proxied no-cache no-store private expired auth; gzip_min_length 1000; ssl_certificate /etc/letsencrypt/live/tejasjadhav2001.tech/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/tejasjadhav2001.tech/privkey.pem; # managed by Certbot #ssl_password_file /etc/ssl/certs/pass.pass; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; # This is a cache for SSL connections ssl_session_cache shared:le_nginx_SSL:1m; ssl_session_timeout 1440m; rewrite ^/(.*)/$ /$1 permanent; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; proxy_buffering on; #proxy_cache STATIC; proxy_cache_valid 200 1d; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_pass https://34.93.29.137:3333; proxy_read_timeout 1m; proxy_connect_timeout 1m; }
请问该问题是由CORS还是SSL证书导致的?
内容的提问来源于stack exchange,提问作者Tejas Jadhav
相关产品推荐
相关产品推荐

