首页 > 解决方案 > 如何从 ngnix.conf 文件中解决基本 URL 中的 www 问题

问题描述

我的 ngnix.conf 文件如下所示.. 我试图在浏览器中点击www.example.com,然后 url 被点击就像https://www.www.example.com// 这给了我 en错误。网址https://example.com也不起作用。

    server {
    #server_names_hash_bucket_size  64;
    listen 80;
    server_name *.example.com www.example.com example.com;
    server_tokens off;
    # Redirects http to https
    location / {
        #return 301 https://$host$request_uri;

        #non www to www
        rewrite ^(.*) https://www.$host$request_uri$1 permanent;
    }

错误就像 -

您的连接不是私密的 攻击者可能试图从 example.com 窃取您的信息(例如,密码、消息或信用卡)。了解更多NET::ERR_CERT_COMMON_NAME_INVALID

注意 - 我的证书还没有过期..

标签: dockernginxssl-certificateno-www

解决方案


我有一个答案。

我以前生成过证书,例如-

sudo certbot certonly --manual \
  --preferred-challenges=dns \
  --email asdf@example.com \
  --server https://acme-v02.api.letsencrypt.org/directory \
  --agree-tos \
  --manual-public-ip-logging-ok \
  -d *.example.com \

现在我已经改变了我的证书生成过程,如下所示 -

sudo certbot certonly --manual \
  --preferred-challenges=dns \
  --email asdf@example.com \
  --server https://acme-v02.api.letsencrypt.org/directory \
  --agree-tos \
  --manual-public-ip-logging-ok \
  -d *.example.com \
  -d example.com

这解决了我的问题。


推荐阅读