问题原文
原帖链接 · adrianTNT · CC BY-SA 4.0
Is it correct to define both listen (80 and 443) under same server {} like this ?
The other method would be to define two separate server{} for each port which I know would be OK.
server {
listen 80 default_server;
server_name example.com;
root /usr/share/nginx/html;
location / {
}
listen example.com:443 ssl; # <<< !!!
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
已采纳解答
原帖链接 · cstoll · CC BY-SA 4.0
As far as I remember, yes it is. Also says so in the documentation (link below):
A single HTTP/HTTPS server
It is possible to configure a single server that handles both HTTP and HTTPS requests:
server { listen 80; listen 443 ssl; server_name www.example.com; ssl_certificate www.example.com.crt; ssl_certificate_key www.example.com.key; ... }
src: https://nginx.org/en/docs/http/configuring_https_servers.html
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
