首页 > 解决方案 > 代理通过 nginx 将 mywebsite 传递到另一个服务器 wordpress 博客

问题描述

我确实将 mywebsite.com/blog 代理传递到另一个服务器,该服务器在该服务器上提供了 wordpress。

当我访问 mywebsite.com/blog 时一切正常,但是当我在 wordpress 管理员上做某事或编辑某事时,它突然重定向到 mywebsite.com/wp-admin 而不是 mywebsite.com/blog/wp-admin

这是我的主要 website.com nginx 配置:

server {
    listen 80;
    server_name mywebsite.com;
    root /var/www/html/laravel-app/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ^~ /blog/ {
        rewrite ^/blog(/?.*)$ $1 break;
        proxy_set_header Host 1.2.3.4;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://1.2.3.4/;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

这是另一个为 wordpress 博客服务的服务器:

server {
    listen 80;

    root /var/www/html/wordpress-blog;

    index index.php;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }
}

标签: wordpressnginx

解决方案


尝试在 Wordpress 数据库上运行这个通用的 mySQL 查询(用 mywebsite.com 和 mywebsite.com/blog 替换 olddomain 和 newdomain):

UPDATE wp_options SET option_value = REPLACE(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE(guid, 'http://olddomain.com','http://newdomain.com');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://olddomain.com', 'http://newdomain.com');

推荐阅读