docker 中的 nginx 在访问 wp-admin 时重定向到本地 ip

docker 中的 nginx 在访问 wp-admin 时重定向到本地 ip

以下是我的 nginx.conf

   events {
  
}
http {
  error_log /etc/nginx/error_log.log  debug;
  client_max_body_size 20m;
  proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
        server {
            listen 80;
            server_name example.org;
            client_max_body_size 1000M;
            location / {
                client_max_body_size 1000M;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                return 301 https://$host$request_uri;
            }
            location /.well-known/acme-challenge/ {
                client_max_body_size 1000M;
                root /var/www/certbot;
            }
        }
        server {
            listen 80;
            server_name www.example.org;
            client_max_body_size 1000M;
            location / {
                client_max_body_size 1000M;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                return 301 https://$host$request_uri;
            }
            location /.well-known/acme-challenge/ {
                client_max_body_size 1000M;
                root /var/www/certbot;
            }
        }
        server {
            listen 80;
            server_name webmin.example.org;
            client_max_body_size 1000M;
            location / {
                client_max_body_size 1000M;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host            webmin.example.org;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                return 301 https://$host$request_uri;
            }
            location /.well-known/acme-challenge/ {
                client_max_body_size 1000M;
                root /var/www/certbot;
            }
        }

        server {
            listen 80;
            server_name portainer.example.org;
            client_max_body_size 1000M;
            location / {
                client_max_body_size 1000M;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host            webmin.example.org;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                return 301 https://$host$request_uri;
            }
            location /.well-known/acme-challenge/ {
                client_max_body_size 1000M;
                root /var/www/certbot;
            }
        }
        server {
            listen 80;
            server_name pgadmin.example.org;
            client_max_body_size 1000M;
            location / {
                client_max_body_size 1000M;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host            pgadmin.example.org;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
                return 301 https://$host$request_uri;
            }
            location /.well-known/acme-challenge/ {
                client_max_body_size 1000M;
                root /var/www/certbot;
            }
        }

        server {
            listen 443 ssl;
            server_name example.org;
            client_max_body_size 1000M;
            ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
            include /etc/letsencrypt/options-ssl-nginx.conf;
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
            location / {
                client_max_body_size 1000M;
                proxy_pass              http://192.168.0.1:7003;
            }
        }

        server {
            listen 443 ssl;
            server_name www.example.org;
            client_max_body_size 1000M;
            ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
            include /etc/letsencrypt/options-ssl-nginx.conf;
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
            location / {
                client_max_body_size 1000M;
                proxy_pass              http://192.168.0.1:7003;
            }
        }

        server {
            listen 443 ssl;
            server_name webmin.example.org;
            client_max_body_size 1000M;
            ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
            include /etc/letsencrypt/options-ssl-nginx.conf;
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
            location / {
                client_max_body_size 1000M;
                proxy_pass              http://192.168.0.1:10000;
            }
        }

        server {
            listen 443 ssl;
            server_name portainer.example.org;
            client_max_body_size 1000M;
            ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
            include /etc/letsencrypt/options-ssl-nginx.conf;
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
            location / {
                client_max_body_size 1000M;
                proxy_pass              http://192.168.0.1:7001;
            }
        }

        server {
            listen 443 ssl;
            server_name pgadmin.example.org;
            client_max_body_size 1000M;
            ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
            ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
            include /etc/letsencrypt/options-ssl-nginx.conf;
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
            location / {
                client_max_body_size 1000M;
                proxy_pass              http://192.168.0.1:7002;
            }
        }
}

以下是我的 nginx docker-compose.yml

version: "3"
  
services:
    nginx:
        image: nginx
        restart: always
        ports:
            - 80:80
            - 443:443
        volumes:
            - "./nginx.conf:/etc/nginx/nginx.conf"
            - ./data/certbot/conf:/etc/letsencrypt
            - ./data/certbot/www:/var/www/certbot
        command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
        networks:
            - dockernet
    certbot:
        image: certbot/certbot
        volumes:
            - ./data/certbot/conf:/etc/letsencrypt
            - ./data/certbot/www:/var/www/certbot
        entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
        networks:
            - dockernet

networks:
    dockernet:
        external: true

以下是我的 wordpress 的 docker-compose.yml

version: "3"

services:
    db:
        build: ./db
        restart: always
        volumes:
            - ${HOME}/wordpress/dbvolume:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: password
    pgadmin:
        restart: on-failure:10
        image: phpmyadmin/phpmyadmin:edge
        environment: 
            PMA_HOST: db
        ports: 
            - 7002:80
        depends_on: 
            - db
    web:
        build: ./web
        depends_on: 
            - db
        environment: 
            WORDPRESS_DB_HOST: db
            WORDPRESS_DB_USER: root
            WORDPRESS_DB_PASSWORD: password
            WORDPRESS_DB_NAME: databasename
        volumes:
            - ${HOME}/wordpress/public_html/:/var/www/html/
        ports: 
            - 7003:80

因此,当我加载https://example.org我的网站时,没有任何问题。但是当我加载时,https://example.org/something/我被重定向到https://192.168.0.1:7003/something/

数据库中的 siteurl 是 example.org。我甚至在 wp-config.php 中添加了 define( 'WP_HOME', 'example.org' ); define( 'WP_SITEURL', 'example.org' );

我在这里做错了什么?主域名可以工作,但为什么我无法加载任何其他页面?我正在使用 Google 计算引擎来设置我的网站。

答案1

  • 由于您的主页正在加载,而其他页面未加载,因此问题可能出在您的迁移上。将 WordPress 网站从一个主机迁移到另一个主机时,可能会丢失部分数据。因此,请确保在迁移过程中已采取所有必要步骤 移动 WordPress地点。

  • 检查您是否编辑了正确的值wp-config.php当前数据库如下:

                     define('DB_NAME, 'db_name');
                     define('DB_USER, 'db_user');
                     define('DB_PASSWORD, 'db_pass');
    
  • 我还建议你检查一下wp_options在您的数据库上,将“siteURL”和“home”修改为您的网站域名。

  • 还可以尝试访问不带尾部斜杠的“https://example.org/something/”。

您也可以参考这个社区问题这可能会对你有帮助。

相关内容