0

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.

AMendis
  • 101
  • 1
  • Check your WordPress configuration. – Michael Hampton Jun 27 '21 at 12:54
  • @MichaelHampton what WordPress configuration to check ? I just moved from one host to another host with same domain – AMendis Jun 27 '21 at 12:58
  • 1
    Check the home and siteurl. This is step #1 for this particular problem with WordPress. – Michael Hampton Jun 27 '21 at 13:03
  • @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 – AMendis Jun 27 '21 at 13:33
  • Did you clear your browser cache? – Michael Hampton Jun 27 '21 at 14:01
  • @MichaelHampton yep. I even tried in incognito mode chrome – AMendis Jun 27 '21 at 14:13
  • 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? – djdomi Jun 27 '21 at 15:59

1 Answers1

0
  • 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.