NGINX - Wordpress infinite redirect loop



我是使用nginx的新手。到目前为止,我一直用作托管引擎APACHE2,因此我的网站迁移遇到了问题

这是我的 VHOST 配置文件:

server {
        root /var/www/html/domain_com/web/;
        index index.php index.html index.htm;
        server_name domain.com www.domain.com;
        error_log /var/www/html/domain_com/log/error.log;
        access_log /var/www/html/domain_com/log/nginx-access.log;
        try_files $uri $uri/ /index.php?$args;
        location ~* .php$ {
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
        }
        include /var/www/html/domain_com/web/nginx.conf; 
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.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 = www.domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name domain.com www.domain.com;
    return 404; # managed by Certbot
}

当我调用网站时,使用这样的配置,它会返回错误"重定向过多",但是如果我在第一个服务器块的顶部添加listen 80;,一切正常,但是 Certbot 在为下一个域添加证书时会显示有关该服务器名称的警告已经存在以及警告被忽略的信息。

我能做些什么来解决这个问题?:)

server {
    listen 80;
    server_name domain.com www.domain.com;
    rewrite ^ https://$server_name$request_uri permanent;
}
server {
        listen 443 ssl; # managed by Certbot
        root /var/www/html/domain_com/web/;
        index index.php index.html index.htm;
        server_name domain.com www.domain.com;
        error_log /var/www/html/domain_com/log/error.log;
        access_log /var/www/html/domain_com/log/nginx-access.log;
        try_files $uri $uri/ /index.php?$args;
        location ~* .php$ {
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
        }
    include /var/www/html/domain_com/web/nginx.conf; 

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

}

相关内容

  • 没有找到相关文章

最新更新