docker - compose 설치 nginx

2912 단어 docker
docker-compose.yml
version: '3.1'
services:
  nginx:
    image: nginx
    restart: always
    container_name: nginx
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./log:/var/log/nginx
      - ./html:/html
      - /etc/letsencrypt:/etc/letsencrypt

nginx.conf
user  nginx;
#nginx    ,    cpu      ,       。
worker_processes  2;

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

events {
	#    worker process            
    worker_connections  1024;
}

http {
	#  mime  ,   mime.type    
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

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

    access_log  /var/log/nginx/access.log  main;

    #  gzip  
    gzip  on;
    gzip_disable "MSIE [1-6].";

    #      
    client_header_buffer_size    128k;
    large_client_header_buffers  4 128k;
	
	#sendfile      nginx      sendfile   (zero copy   )     ,
	#      ,     on,
    #             IO     ,     off,
    #        I/O    ,     uptime.
    sendfile on;
	
	#                  ,                  。
    #keepalive_timeout  0;
    keepalive_timeout  120; 
	
	#                
	client_max_body_size 50m;
	
	#      hash   
	server_names_hash_bucket_size 128;
	#header            
	underscores_in_headers on; 
	
	#down      server       
	#weight       ,   1。weight  ,        。
	#backup      ,        backup            ,    backup  ,           。
	#max_fails             1。        ,  proxy_next_upstream        
	#fail_timeout max_fails    ,     。
	#apiServer      ,      
	upstream apiServer {
      server 172.17.0.1:18081 weight=10;
      server 172.17.0.1:28081 weight=10;
    }

    # http   https
    server{
		listen 80;
		server_name www.xxxx.com     .xxxx.com;
		rewrite ^ https://$http_host$request_uri? permanent;
	}

	server{
		listen 80;
		server_name www.xxxx.com;
		location / {
			root /html/xxxx;
			index index.html index.htm;
		}
	}
	
	server{
		listen 80;
		server_name xx.xxxx.com;
		location / {
			try_files $uri $uri/ @router;
			root /html/xx;
			index index.html index.htm;
		}
		location /api {
			rewrite ^/api/?(.*)$ /$1 break;
			include uwsgi_params;
            proxy_pass http://apiServer;
		}
		proxy_set_header   Host             $host;
		proxy_set_header   X-Real-IP        $remote_addr;						
		proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
}

README.md
#       
docker exec -it nginx service nginx check-reload
#         
docker exec -it nginx service nginx reload

좋은 웹페이지 즐겨찾기