Letsencrypt Docker 中的 Nginx 重定向循环与多个站点

Letsencrypt Docker 中的 Nginx 重定向循环与多个站点

当我尝试访问自己的网站时,我收到“重定向错误过多”的提示。这些网站托管在我的服务器上,使用 Letsencrypt Docker 中的 Nginx(Docker Hub:https://hub.docker.com/r/linuxserver/letsencrypt/)。它会重定向到相同的 URL,例如https://example.com/->https://example.com/

这是我的配置:

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

server {
    listen 443 ssl;

    root /www/site1_com/www/public_html;
    index index.php index.html;

    server_name www.site1.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

-

server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

-

server {
    listen 443 ssl;

    root /config/www/site2.com/public_html;
    index index.php;

    server_name site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

server {
    listen 443 ssl;

    root /config/www/site2.com/img;
    index index.php;

    server_name img.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

}

server {
    listen 443 ssl;

    root /config/www/site2.com/upload;
    index index.php;

    server_name upload.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;



    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

-

server {
    listen 443 ssl;

    server_name cloud.site4.me;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        include /config/nginx/proxy.conf;
        proxy_max_temp_file_size 2048m;
        proxy_pass https://10.0.0.254:443;
    }
}

ps:该 Nginx 实例上托管了多个网站,其中一些可以运行,有些则不能

更新的配置:

站点1(工作):

server {
    listen 443 ssl;
    server_name site1.net;
    return 301 https://www.site1.net$request_uri;
}

server {
    listen 443 ssl;

    root /config/www/site1.net/www/public_html;
    index index.php index.html;

    server_name www.site1.net;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

site2(不工作,使用工作站点的根目录进行测试):

server {
    listen 443 ssl;

    root /config/www/site1.net/www/public_html;
    index index.php index.html;

    server_name www.site2.com;

    # all ssl related config moved to ssl.conf
    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php7-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php7-fpm:
        #fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
    }
}

相关内容