Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

django - Docker Wordpress/Apache behind Docker Nginx - Port Number Issue

I am having problems getting the wordpress docker image working with the nginx docker image.

The python/django container works perfectly fine with nginx, but the wordpress/apache one is having problems. I can get to the django site, with https. I cannot get into the wordpress one with https. In fact, when I go to my site site.com/wp, I get back site.com:8080/wp, so for some reason it is coming back through port 8080, and not 443 or 80. I've tried setting the wordpress site as the root location / (in the default.conf file) and it still has the same problem (then I get site.com:8080). The wordpress functionality is normal, I can edit the site as usual.

default.conf file for nginx

disable_symlinks off;
ssl_certificate xxx
ssl_certificate_key xxx

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name site.com;

    location / {
        proxy_pass http://django:8000; #django container
    }

    location /static {
        alias /path/to/static;
    }

    location /wp {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;        
        proxy_pass http://wordpress:80; #the wordpress container
    }
}

docker yml

version: '3.7'

services:
  django:
    restart: always
    build: 
      context: .
      dockerfile: docker-django #django gunicorn server, python image
    ports:
      - "8000:8000"

  wordpress:
    restart: always
    build:
      context: .
      dockerfile: docker-wordpress #docker wordpress-apache image
    # image: wordpress:latest
    volumes:
      - ./www/html:/var/www/html
      - ./etc/apache2:/etc/apache2
    ports:
      - "8080:80"

  nginx:
    restart: always
    build: 
      context: .
      dockerfile: docker-nginx #docker nginx image
    # image: nginx
    volumes:
      - ./xx/static:/usr/xx/static
      - ./nginx/conf.d:/etc/nginx/conf.d
    ports:
      - "443:443"
      - "80:80"
    depends_on:
      - django
      - wordpress
question from:https://stackoverflow.com/questions/66056395/docker-wordpress-apache-behind-docker-nginx-port-number-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems like the wordpress container is pulling that 8080 port number from mysql, where I had it originally set for local testing.

Overriding the mysql stored site name worked for me, by adding these lines to wp-config.php

define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_SITEURL', 'https://' . $_SERVER['SERVER_NAME'] . '/' );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...