Answer a question

I use Docker-compose to develop the WordPress website together with Mysql and PHPMyAdmin. Also, use Portainer to monitor them, showing the health icon, and I can access it by typing the IP address 192.168.188.80:3001, and I can curl the page from port 3001.

I try to assign the domain name for the different containers, there will have a couple of WordPress websites and I plan to host them on ports 3001, 3002, 3003...

I enable the conf file in Nginx and the conf file like

server {
  listen 80;
  server_name forktruck.bcsystems.nz;

  location / {
    proxy_pass http://0.0.0.0:3001;
  }
}

The yml file is here

version: '3.8'

volumes:
  wp-forktruck-data:
networks:
  wp-forktruck-network:

services:

  db:
    image: mysql:latest
    volumes:
      - ./wp-forktruck-data:/var/lib/mysql
    environment:
       MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
       MYSQL_DATABASE: wordpress-forktruck
       MYSQL_USER: wp-forktruck
       MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    ports:
      - 3201:3306  
    healthcheck:
      test: curl --fail http://localhost || exit 1
      interval: 300s
      start_period: 5s
      timeout: 10s
    restart: always
    networks:
      - wp-forktruck-network

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
      MYSQL_USER: wp-forktruck
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    ports:
      - 3101:80
    healthcheck:
      test: curl --fail http://localhost || exit 1
      interval: 300s
      start_period: 5s
      timeout: 10s
    networks:
      - wp-forktruck-network

  wordpress:
    depends_on:
      - db
    image: wordpress
    ports:
      - 3001:80
    healthcheck:
      test: curl --fail http://localhost || exit 1
      interval: 300s
      start_period: 5s
      timeout: 10s
    environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wp-forktruck
       WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
       WORDPRESS_DB_NAME: wordpress-forktruck
    volumes:
      - ./forktruck:/var/www/
    container_name: wp-forktruck
    networks:
      - wp-forktruck-network

but something wrong and the domain name got 520 error.

Answers

you need to add the redirect option in nginx

server {
  listen 80;
  server_name forktruck.bcsystems.nz;

  location / {
    proxy_pass http://0.0.0.0:3001;
    proxy_read_timeout  90;
    proxy_redirect http://0.0.0.0:3001 http://forktruck.bcsystems.nz/;
  }
}

And should work, good luck

Logo

更多推荐