【发布时间】:2021-12-29 08:14:44
【问题描述】:
我正在尝试在运行 Nginx 的 Ubuntu 服务器上建立一个新网站。我已经设置了目录,但出现了一些意外行为。
这是我的服务器块:
server {
listen 80;
listen [::]:80;
root /var/www/website.org;
index index.html index.htm index.nginx-debian.html;
server_name website.org www.website.org;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name website.org www.website.org;
root /var/www/website.org;
index index.html index.htm index.nginx-debian.html;
ssl_certificate /etc/letsencrypt/live/website.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website.org/privkey.pem;
ssl_session_cache shared:SSL:5m;
ssl_trusted_certificate /etc/letsencrypt/live/website.org/chain.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
add_header Strict-Transport-Security "max-age=31536000" always;
location / {
try_files $uri $uri/ =404;
}
}
我一遍又一遍地经历过这件事。我检查了我的防火墙,它似乎设置得很好。我有几个问题:
- 根据我的研究,这个服务器设置应该是正确的。我错过了什么?
- 我想使用 HTTPS 处理我的站点的“www”前缀和无前缀版本。行为将是非 https 将自动重定向到 https。因此,我在端口 80 服务器块中包含了 return 语句。 “www”子域是否需要单独的 SSL 证书?我最初制作 SSL 证书时是否应该包括在内?我该怎么做?
- 我可以对服务器块使用通配符语法来捕获“www”子域吗?那会是不好的做法吗?
【问题讨论】:
-
您是否在主机文件中添加了域?
-
您是否为文件创建了符号链接?
-
@Kevin 我确实做了符号链接
-
@Forbidden 我没有在主机文件上做域。那里需要什么?
-
您指的“意外行为”是什么?