【发布时间】:2021-05-28 16:06:59
【问题描述】:
我正在使用自签名证书和 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}.`));
node 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';
}
}
【问题讨论】:
-
“我突然收到一个 cors 错误”——这到底是什么意思?
-
"ssl 协议错误" — 到底是什么意思?
-
@Quentin 错误是那个模糊的
myip:60702/user/login:1 Failed to load resource: net::ERR_SSL_PROTOCOL_ERRORorCross-source (cross-origin) request blocked: The same-source rule prohibits reading the external resource at https://myip:60702/user/login. (Reason: CORS request failed). -
直接请求网址。在地址栏中输入它。它可能会为您提供有关 SSL 错误的更多信息。
-
@Quentin Postman 给我:
Error: write EPROTO 1284230808:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:或更清晰的 curl:curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number