nginx www vhost,未重定向到非www https://网站

时间:2020-06-11 11:12:30

标签: nginx virtualhost nginx-config

我有一个可以使用的网站

domain.com --> redirects to https://example.com
https://example.com --> works fine
https://www.example.com --> redirects to https://example.com --> works fine
www.example.com --> 404 error --> should redirect to https://example.com

这是我的虚拟主机,名称为example.com

    server {
   server_name myip domain.com www.example.com;
   root /var/www/cra-myapp/myapp/LandingPage/my-default-starter/public;
   index index.html index.htm;
   location / {
   try_files $uri /index.html =404;
   }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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


}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


   server_name myip example.com;
    listen 80;
    return 404; # managed by Certbot


}

server {
   listen 443;
   server_name www.example.com;
   return 301 https://$server_name$request_uri;
}

这里有什么问题?我生成了ssl配置,并添加了一些配置块

sudo certbot --nginx -d example.com -d www.example.com

0 个答案:

没有答案