[英]cors error with nginx, node and vue when using SSL
我正在使用自签名证书和 nginx 让 https 在我的服务器上工作。 没有 https 我没有错误。 但是在使用 https 时,我突然收到 cors 错误(firefox)/ ssl 协议错误(chrome)。 我在后端和 nginx vue 配置中启用了 cors。
在 app.js 中:
app.options('*', cors())
app.use(cors());
// Still using http module cause nginx is doing https stuff
const listener = app.listen(nconf.get('port'), () => console.log(`Ready on port ${listener.address().port}.`));
节点 nginx conf 看起来像:
listen 443 ssl;
listen [::]:443 ssl http2;
server_name localhost;
# point to ssl certificate path
include snippets/bcknd/self-signed.conf;
include snippets/bcknd/ssl-params-bck.conf;
root /var/www/server/pvapp-server;
location / {
proxy_pass http://localhost:60702;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_ssl_verify off;
}
vue nginx 配置看起来像:
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name inf-education-67.umwelt-campus.de;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
# point to ssl certificate path
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location / {
# point to dist folder inside vue source code folder
root /var/www/client/pvapp-client/dist;
autoindex on;
autoindex_exact_size off;
index index.html index.htm;
try_files $uri $uri/ /index.html;
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}
您从myip:60702
收到 SSL 错误,但您的代码proxy_pass http://localhost:60702
因此该端口未运行 ZEA52C36203C5F99C3CE2442D531 服务。 它是普通的 HTTP。
您需要向实际使用 HTTPS 的 URL 发出 HTTPS 请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.