我有一个简单的问题.我只是想知道我是否喜欢:
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
...
}
如果我输入URL http://example.com,这会自动将我从http重定向到https吗?
它适用于我,但我不确定它是否适用于每个人,这就是我要问的原因.
提前致谢.
最佳答案
不,通常需要这样的东西才能进行转发.
如果它已经有效,那么其他东西就可以做到.是否安装了其他Web服务器?你在使用可能正在做CDN的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;
}