【问题标题】:NGINX - Wordpress infinite redirect loopNGINX - Wordpress 无限重定向循环
【发布时间】:2019-08-31 01:25:28
【问题描述】:

我是使用 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 在为下一个域添加证书时显示有关该服务器名称已存在的警告以及警告已被忽略的信息。

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

【问题讨论】:

    标签: wordpress nginx dns redirect-loop


    【解决方案1】:
    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
    
    
    }
    

    【讨论】:

    • nginx: [emerg] 未知指令 "if($scheme" in /etc/nginx/sites-enabled/domain_com:33
    • 我应该在 /etc/nginx/nginx.conf 文件中定义一些东西吗?
    • 嘿更新配置。你用的是哪个版本的 nginx?
    • nginx版本:nginx/1.14.0
    • 配置更新后,出现与之前相同的错误(“重定向太多”)
    猜你喜欢
    • 2013-11-27
    • 2015-02-26
    • 2023-03-19
    • 2015-12-09
    • 1970-01-01
    • 2011-06-04
    • 2021-10-21
    • 2011-03-29
    • 1970-01-01
    相关资源
    最近更新 更多