Nginx + apache + wordpress example.com/wp-admin 重定向到 example.com:8080/wp-admin

Nginx + apache + wordpress example.com/wp-admin 重定向到 example.com:8080/wp-admin

我在端口 443 上运行 Nginx,作为端口 8080 上的 apache 的反向代理,apache 为 wordpress 处理 php 文件。我已经设置了 wordpress,除了 wp-admin 之外,一切都运行正常。当我把https://example.com/wp-admin在我的浏览器中,它会将我重定向到 example.com:8080/wp-admin。我该如何修复它?

server {
listen              443 ssl http2 default_server;
server_name         example.com;
set                 $base /home/www/example.com;
root                /home/www/example.com/public;

# SSL
ssl_certificate     /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
access_log          /var/log/nginx/example.access.log;
error_log           /var/log/nginx/example.error.log warn;
# security
include             snippets/security.conf;
# additional wordpress config
include             snippets/wordpress.conf;
include             snippets/performance.conf;
server_name_in_redirect off;
index index.php;
location / {
    try_files $uri @apache;
}

location ~* \.php$ {
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;
    proxy_pass http://127.0.0.1:8080;
    access_log off;
    log_not_found off;
}

location @apache { # used by location /
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port  $server_port;
    proxy_pass http://127.0.0.1:8080;
    access_log off;
    log_not_found off;

}

答案1

您需要在 WordPress 中正确设置站点根 URL。例如,在 中wp-config.php添加以下内容:

define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');

相关内容