005 docker-compose nginx

  1. docker-compose.yml
version: '3.1'
services:
  nginx:
    image: nginx
    container_name: nginx
    privileged: true
    restart: always
    ports:
      - 80:80
    volumes:
      - /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - /opt/nginx/logs:/var/log/nginx
      - /opt/nginx/html:/usr/share/nginx/html
      - /opt/nginx/cert/:/etc/nginx/cert/

  1. nginx.conf
vim /opt/nginx/conf/nginx.conf
user root;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream gateway.daqing.zhongxinda.top {
        server 172.26.191.107:7777 weight=1;    #此处ip为服务器内网IP,端口号为tomcat端口号
        #server 172.26.191.108:7777 weight=1;    #此处ip为服务器内网IP,端口号为tomcat端口号
    }

    server {
        listen       80;
        server_name  api;
        location /prod-api/ {
            proxy_pass http://gateway.daqing.zhongxinda.top/;
        }
        location /daqing/ {
            proxy_pass http://gateway.daqing.zhongxinda.top/;
        }

        location / {
            root /usr/share/nginx/html/daqing/dist;
            try_files $uri $uri/ @router;
            index  index.html index.htm;
            expires 30d; #缓存30天
        }

        location @router {
            rewrite ^.*$ /index.html last;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

你可能感兴趣的:(005 docker-compose nginx)