具有别名域重定向到主域的Nginx虚拟主机不起作用

时间:2020-10-29 16:44:35

标签: nginx

安装具有多个域名的虚拟主机后,我喜欢将所有主机重定向到主域。

我在读取Pitfalls and Common Mistakes之后但仅在服务器页面上尝试,但没有重定向到主域

#
# Note: This file must be loaded before other virtual host config files,
#
# HTTP

server {
    server_name host01.mydomain.es;
    return 301 $scheme://web.mydomain.es$request_uri;
}

server {
    # Listen on ipv4

    server_name web.mydomain.es;
    # host01.mydomain.es www.mydomain.es;

    # Redirect all insecure http:// requests to https://
    # return 301 https://$host$request_uri;
    root /home/albarid/web/albarid/public;

    index index.html index.htm index.php;

    charset utf-8;

    #listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/host01.mydomain.es/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/host01.mydomain.es/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 = host01.mydomain.es) {
        return 301 https://web.mydomain.es$request_uri;
    } # managed by Certbot

0 个答案:

没有答案