1.下载镜像
docker pull nginx
2.启动镜像复制要挂载的文件
docker run --name nginx -p 80:80 -p 443:443 --network mynet -d nginx:1.17.6
3.从容器中复制配置文件
docker cp nginx:/etc/nginx/ /home/docker/
docker cp nginx:/etc/nginx/nginx.conf /home/docker/nginx/nginx.conf
docker cp nginx:/etc/nginx/conf.d /home/docker/nginx/
docker cp nginx:/var/log/nginx /home/docker/nginx/logs
docker cp nginx:/etc/nginx/modules/ /home/docker/nginx/
docker stop nginx
docker rm nginx
chmod 777 /home/docker/nginx/nginx.conf
5.启动
docker run --name nginx -p 80:80 -p 443:443 --restart always --network mynet -v /home/apollo/webapp:/usr/share/nginx/html -v /home/docker/nginx:/etc/nginx -v /home/docker/nginx/logs:/var/log/nginx -v /home/docker/nginx/modules:/etc/nginx/modules -d nginx:1.17.6
6.nginx.conf配置
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
upstream apolo{
server 192.79.68.212:50001;
server 192.79.68.212:50002;
server 192.79.68.212:50003;
server 192.79.68.212:50004;
server 192.79.68.212:50005;
server 192.79.68.212:50006;
server 192.79.68.212:50007;
server 192.79.68.212:50008;
server 192.79.68.212:50009;
server 192.79.68.212:50010;
}
server {
listen 80;
proxy_pass apolo;
}
}
http {
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
deafult.conf配置
upstream apollo_server {
server 120.79.68.212:9302 weight=1;
}
server
{
listen 443;
root /usr/share/nginx/html/apollo-web;
index index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ /index.html;
server_name apollo2.hored.net;
ssl on;
ssl_certificate cert/6785813__hored.net.pem;
ssl_certificate_key cert/6785813__hored.net.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location /nginx_status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\. {
deny all;
}
location /api {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forewarded-For $remote_addr:$remote_port;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 50M;
proxy_set_header Port 443;
proxy_pass http://apollo_server/;
}
}