Skip to content

謝雅如-Day2-240702 #38

@HsiehBubu

Description

@HsiehBubu

ngx.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;

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

Compose.yaml

services:
  ngnix:
    image: nginx:latest
    container_name: ngnix_user2
    ports:
      - "8089:80"
    environment:
      - NGINX_HOST=foobar.com
      - NGINX_PORT=80
    volumes:
      - ./ngx.conf:/etc/nginx/nginx.conf:ro
    command: [nginx-debug, '-g', 'daemon off;']
    restart: unless-stopped
  wordpress:
    image: wordpress:latest
    container_name: wordpress_user2
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: user
      WORDPRESS_DB_NAME: root
  mysql:
    image: mysql:latest
    container_name: mysql_user2
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: root
      MYSQL_USER: user
      MYSQL_PASSWORD: user
    volumes:
      #-db-vol:/var/lib/mysql
      - /home/user-2/db:/var/lib/mysql
    logging:
      driver: gelf
      options:
        gelf-address: udp://127.0.0.1:12201
    healthcheck:
      test:
        [
         'CMD-SHELL',
         'mysqladmin ping -h localhost -u root --password=root || exit 1',
        ]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped

#volumes:
   #db-vol:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions