首页 > 解决方案 > WordPress 登录重定向不适用于 Nginx 根目录

问题描述

我有一个 wordpress 网站,它将我重定向到请求登录的上一页。它在 apache Web 服务器上运行良好,并可在http://localhost/wp上访问,当我从 apache 移动到 nginx 时,它在 nginx 子目录(/var/www/html/wp)中也可以正常运行,即http://localhost /wp。但是当我在 nginx 根目录(即 /var/www/html/)上部署站点时,登录重定向停止工作并停留在登录页面上。有人可以识别我在配置或重定向代码中做错了什么。

子目录工作正常:

http://localhost/wp/gallery ----> http://localhost/wp-login.php ----> 重定向到 ---> http://localhost/wp/gallery

从根目录:

我想要的是

http://localhost/gallery ----> http://localhost/wp-login.php ----> 重定向到 ---> http://localhost/gallery

它能做什么

http://localhost/gallery ----> http://localhost/wp-login.php ----> 重定向到---> http://localhost/wp-login.php

在此处重定向功能代码:

session_start();
 if(wp_get_referer() != get_site_url()."/wp-login.php"){
    $_SESSION['back_log'] = wp_get_referer();
 }
 function admin_default_page() {
    $back_log = "";
    if(isset($_SESSION['back_log']) && !empty($_SESSION['back_log'])) {
        $back_log = $_SESSION['back_log'];
        return $back_log;
    }
 }
 add_filter('login_redirect', 'admin_default_page');

给出了构形

 server {
        listen       80;
        server_name  localhost;
        client_max_body_size 64M;
        #proxy_max_temp_file_size 0;
        #proxy_buffers 16 16k;  
        #proxy_buffer_size 16k;

        root html/;
        index  index.php index.html index.htm;


        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;
        }    

        location / {
                try_files $uri $uri/ /index.php$is_args$args ;
                
            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass   127.0.0.1:9999;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
   

        location /wp {
        root html/wp;
        try_files $uri $uri/ /wp/index.php$is_args$args;
        }
        
        location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9999;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        }

    }

标签: phplinuxwordpressnginx

解决方案


推荐阅读