Score:0

nginx in docker redirects to local ip when accessing wp-admin

dk flag

Below is my 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;
            }
        }
}

below is my docker-compose.yml for nginx

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

below is my docker-compose.yml for wordpress

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

So when I load https://example.org my site loads without any problem. BUT when I load https://example.org/something/ I'm getting redirected to https://192.168.0.1:7003/something/

siteurl is example.org in database. I even added define( 'WP_HOME', 'example.org' ); define( 'WP_SITEURL', 'example.org' ); to wp-config.php

What am I doing wrong here ? Main domain works but why I can't load any other page ? I'm using google compute engine to setup my site.

Michael Hampton avatar
cz flag
Check your WordPress configuration.
AMendis avatar
dk flag
@MichaelHampton what WordPress configuration to check ? I just moved from one host to another host with same domain
Michael Hampton avatar
cz flag
Check the home and siteurl. This is step #1 for this particular problem with WordPress.
AMendis avatar
dk flag
@MichaelHampton siteurl is https://example.org in database. I even added define( 'WP_HOME', 'http://example.org' ); define( 'WP_SITEURL', 'http://example.org' ); to wp-config.php
Michael Hampton avatar
cz flag
Did you clear your browser cache?
AMendis avatar
dk flag
@MichaelHampton yep. I even tried in incognito mode chrome
djdomi avatar
za flag
Remind in case of WordPress to disable the cache plugins as they often the reason for broken WordPress installations, however, why are the same domains and sub-domains been used in so many extra server blocks I can't see a difference in the configuration except that it makes it more complicated to your self?
Score:0
us flag
  • As your homepage is loading and other pages are not loading the problem would be with your migration. While moving a wordpress site from one host to another host, there could be partial data loss. So make sure that you have undertaken all the necessary steps while moving WordPress site.

  • Check if you have edited the correct values in wp-config.php for current database as below:

                     define('DB_NAME, 'db_name');
                     define('DB_USER, 'db_user');
                     define('DB_PASSWORD, 'db_pass');
    
  • I would also suggest you to check wp_options on your database as well, modify ‘siteURL’ and ‘home’ as your web domain.

  • Also try to access ‘https://example.org/something/’ without trailing slash.

You can also refer to this community question that might help you.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.