小编Gri*_*box的帖子

如何使用 HTTPS 和 nginx 的 certbot 将 www 重定向到非 www

我试图将 www 重定向到非 www,但它不起作用。我尝试过类似问题的各种答案,但没有成功。

我使用 certbot 为 3 个域提供了 SSL 证书example.comwww.example.com并且admin.example.com.

这是我当前的配置,适用于非 www 和管理员,但 www.example.com 不起作用。

# HTTP - redirect all requests to HTTPS
server {
    listen 80;
    listen [::]:80;
    return 301 https://$host$request_uri;
}

# Redirect to non-www
server {
    server_name www.example.com;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.se/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.se/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    return …
Run Code Online (Sandbox Code Playgroud)

https nginx ssl-certificate certbot nginx-config

10
推荐指数
1
解决办法
9561
查看次数

标签 统计

certbot ×1

https ×1

nginx ×1

nginx-config ×1

ssl-certificate ×1