Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

nginx配置问题 为什么加上www跳转不过去呢?

输入domain.top可以跳转到https://domain.top
但是输入www.domain.top却跳转不到https://domain.top怎么办?这个应该怎么配置呢?
就是想统一跳转到https://domain.top

server{                                                     
         listen 80;
         server_name www.domain.top domain.top;
         return 301 https://domain.top$uri;
}

server {
        listen 443 ssl;
        server_name domain.top;
        client_max_body_size 20M;
        ssl on;
        ssl_certificate /etc/nginx/ssl/1_domain.top_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/2_domain.top.key;
        set $root_path '/var/www/html/domain';  
        root $root_path;  
      
        index index.php index.html index.htm;  
      
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

简单,你把server_name匹配规则改为:*.domain.top
然后 nginx -t nginx -s reload


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...