我有一个域sub.example.com,它在Ubuntu服务器上配置并完全运行。我使用Certbot来使用HTTPS配置域,但是我也配置了API,可以在该域的特定端口上访问,比如2500。当我访问example.com时,我会看到显示站点是安全的锁,但是每当我进入example.com:2500/api/someAPI时,API都会返回适当的结果,但是站点并不安全。由于主站点是安全的,而API访问位置不是安全的,所以我无法相应地进行API调用,从而导致net::ERR_SSL_PROTOCOL_ERROR。
堆叠:
一段时间前,我能够在另一个VPS (DigitalOcean)和域上使用相同的精确技术,但我相信我从未遇到过这个问题。
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}发布于 2020-03-02 05:09:18
我解决了我的问题。事实证明,它与nginx配置无关。相反,在定义和公开API的node.js文件中,我需要包括HTTPS访问。为了做到这一点,我在代码中添加了以下行:
const https = require('https');
const httpsOptions = {
cert: fs.readFileSync("/etc/letsencrypt/live/<domain>/fullchain.pem"),
key: fs.readFileSync("/etc/letsencrypt/live/<domain>/privkey.pem")
}
https.createServer(httpsOptions, app).listen(port);其中<domain>被托管在其上的域名所取代。
发布于 2020-02-28 22:35:08
默认情况下,除了端口443之外,没有其他端口使用安全连接。但是,如果指定这样做(例如使用https://example.com:2500),则应该安全地连接。如果希望它自动完成此操作,则需要在web服务器应用程序设置中配置它。如果您知道用于承载服务器的应用程序(例如。如果您有编辑配置文件的权限,那么您应该能够配置这个配置文件。
编辑:对不起,我最初没有看到你将问题标记为使用nginx。在使用nginx之前,我还没有专门这样做,但是我找到了解释这个过程的本教程。在/etc/nginx/sites available/example.com中,您应该能够将“List443 ssl”更改为"listen 443,2500 ssl;“以便在多个端口上侦听。此外,还可以添加return 301 https://$host$request_uri;,以便将连接重定向到https安全连接(请参阅https://serversforhackers.com/c/redirect-http-to-https-nginx)。
我希望这能帮到你!
https://stackoverflow.com/questions/60460045
复制相似问题