我有一个简单的问题。我只是想知道我是否有类似情况:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
...
}
如果我输入 URL,这会自动将我从 http 重定向到 https 吗?http://example.com?
它对我有用,但我不确定它是否对每个人都有用,这就是我询问的原因。
提前致谢。
答案1
不,通常需要这样的东西来进行转发。
如果它已经运行,则可能是其他程序在执行此操作。是否安装了其他 Web 服务器?您是否使用了可能执行此操作的 CDN?
server {
server_name example.com;
listen 443 ssl http2;
// etc - main server
}
# Forward non-www requests to www
server {
listen 80;
server_name example.com www.example.com;
access_log /var/log/nginx/access.log main buffer=128k flush=1m if=$log_ua;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.example.com;
ssl_certificate /var/lib/acme/certs/***CERT_DIRECTORY/fullchain;
ssl_certificate_key /var/lib/acme/certs/***CERT_DIRECTORY/privkey;
# Set up preferred protocols and ciphers. TLS1.2 is required for HTTP/2
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
access_log /var/log/nginx/access.log main buffer=128k flush=1m if=$log_ua;
return 301 https://www.example.com$request_uri;
}