搜索 Docker之docker-compose单机编排,有模版
version: '3.5'services:nginx:image: nginx:latestrestart: alwaysvolumes:- ./html:/usr/share/nginx/html- ./conf/nginx.conf:/etc/nginx/nginx.conf- ./conf/conf.d:/etc/nginx/conf.d- ./logs:/var/log/nginxports:- "80:80"
nginx.conf
worker_processes 1;
events {worker_connections 1024;
}
http {include 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" $request_time $upstream_response_time ';sendfile on;keepalive_timeout 65;gzip on;fastcgi_buffers 8 128k;include conf.d/*.conf;
}
conf.d/demo.conf
upstream backendserver{server 192.168.22.3:8080;
}
upstream backendserver2{server 192.168.22.2:8080;
}
server {listen 80;listen 443 ssl;server_name demo.xx.com;index index.html;root /usr/share/nginx/html/demo.xx.com;client_max_body_size 100M;ssl on; ssl_certificate /etc/nginx/conf.d/cert/demo.xx.com/demo.xx.com.pem;ssl_certificate_key /etc/nginx/conf.d/cert/demo.xx.com/demo.xx.com.key;ssl_session_timeout 5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers on; if ($scheme = http) {return 301 https://$host$request_uri;}location ~* \.html$ {root /usr/share/nginx/html/demo.xx.com;add_header Cache-Control no-store;add_header X-Frame-Options SAMEORIGIN;}location = /{root /usr/share/nginx/html/demo.xx.com;add_header Cache-Control no-store;add_header X-Frame-Options SAMEORIGIN;}location ^~ /api {proxy_connect_timeout 3000;proxy_send_timeout 3000;send_timeout 3000;proxy_read_timeout 3000;proxy_set_header Host $http_host;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://backendserver;}location / {root /usr/share/nginx/html/demo.xx.com;try_files $uri $uri/ @backend;}location @backend {proxy_connect_timeout 3000;proxy_send_timeout 3000;send_timeout 3000;proxy_read_timeout 3000;proxy_set_header Host $http_host;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://backendserver2;}access_log /var/log/nginx/demo.xx.com.access.log main; error_log /var/log/nginx/demo.xx.com.error.log ; }