srcmesh-workshop / docker-workshop

0 stars 40 forks source link

蘇俊 #26

Open chunsu-tw opened 6 days ago

chunsu-tw commented 6 days ago

蘇俊

docker-compose.yml

services:
  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 23895858
      MYSQL_USER: cm0278
      MYSQL_PASSWORD: 23895858
      MYSQL_DATABASE: mysql_db
    volumes:
      - db_file:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 30s
      timeout: 10s
      retries: 3

  wordpress:
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: cm0278
      WORDPRESS_DB_PASSWORD: 23895858
      WORDPRESS_DB_NAME: mysql_db
    volumes:
      - db_file:/docker-workshop/day2/hands-on-blog/cm0278
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 30s
      timeout: 10s
      retries: 3

  nginx:
    image: nginx
    restart: always
    ports:
      - "8666:80"
    volumes:
      - ../cm0278/nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - wordpress

volumes:
  db_file:

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    # Path to access.log & error.log
    access_log /var/log/nginx/access.log  main;
    error_log /var/log/nginx/error.log  warn;

    sendfile        on;
    keepalive_timeout  65;
    gzip  on;

    upstream backend {
        # must match the target service name
        server wordpress:80;
    }

    server {
        listen       80;
        location / {
            # $http_host is the host name that users seen on the browser URL
            # and it equals to `HTTP_HOST` request header.
            proxy_set_header Host $http_host;

            # You have to change this according to your setup.
            proxy_pass http://wordpress:80;

            # Modify `Location` of 301 or 302 HTTP response, so
            # that the browser will follow the correct location.
            proxy_redirect ~^http://[^/]*/(.*) http://$http_host/$1;
        }
    }
}