Wordpress + Nginx Virtual host

Sorry I’m new to Docker.

How can i use nginx as virtual host ? Right now, to access my wordpress installation i go to http://localhost:8080 . . who can i make set this to http://test.dev which is i set in my nginx.conf file. ?

here is my files
docker-compose.yml

version: '3.3'

services:
  db: # container name
    image: mariadb # pulls latest mariadb image
    volumes:
       - db_data:/var/lib/mysql
       # - ./database:/docker-entrypoint-initdb.d
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: copywriters
      MYSQL_PASSWORD: password
  
  wordpress: # container name
    depends_on:
      - db
    volumes:
      - ./wordpress:/var/www/html
    image: wordpress:latest # pulls latest wordpress image
    ports:
      - "8080:80"
    restart: always
    environment:  # this will be written to wp-config.p
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: copywriters
      WORDPRESS_DB_PASSWORD: password
      WORDPRESS_TABLE_PREFIX: wp_

  nginx:
    image: nginx:latest
    ports:
        - '80:80'
    volumes:
      - ./logs/nginx/:/var/log/nginx/
      - ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./www/:/usr/share/nginx/html
    links:
        - wordpress
    restart: always
    
volumes:
    db_data:

nginx.conf

events {}

http {
    include			/etc/nginx/mime.types;
    default_type  	application/octet-stream;
    
    server {
        listen       80;
        server_name  test.dev;

        root /var/www/html;
        index index.php index.html index.htm;

        location / {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
        }
    }
}

Hope you can help me… Thank You… :slight_smile:

Do you have ‘test.dev’ defined in your DNS or in your hosts file?

You need to add a virtual host in /etc/hosts like this:

127.0.0.1 myvirtualdomain.dev

Next you can access to your app with that domain name.