1、先从Docker HUB中摘取最新版本的nginx镜像: docker image pull nginx
2、创建临时nginx容器: docker container run -d --name nginx_temp nginx
3、将nginx_temp容器中nginx的配置路径拷贝到所在主机:
docker cp nginx_temp:/etc/nginx/nginx.conf /root/docker/nginx/conf
docker cp nginx_temp:/etc/nginx/conf.d/default.conf /root/docker/nginx/conf/conf.d
4、删除临时nginx容器:docker container rm -f nginx_temp
5、创建正式nginx容器:docker run --privileged -it -p 80:80 --name nginx -v /root/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/docker/nginx/conf/conf.d:/etc/nginx/conf.d -v /root/docker/nginx/html:/usr/share/nginx/html -v /data/docker/nginx/logs:/var/log/nginx -v /root/docker/nginx/certDownload:/usr/share/nginx/cert/data/certDownload -d nginx
6、linux 安装ping命令
apt-get update && apt-get install iputils-ping
7、显示所有容器ip
docker inspect --format=’{{.Name}} - {{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ $(docker ps -aq)
8、nginx配置:
添加 a):
upstream hello{
server 172.17.0.3:8080;
}
server {
listen 80;
server_name 10.192.1.62;
location /{
proxy_pass http://hello;
index index.html index.htm;
}
}
添加 b):client_max_body_size 50m;
9、nginx搭建文件服务器配置:
# 需要把user改为root,否则文件服务器会报没有权限访问文件
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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;
client_max_body_size 100m;
#gzip on;
upstream hqcm {
server 172.17.0.2:8080;
}
server {
listen 80;
server_name 127.0.0.1;
location /{
add_header Content-Disposition attachment;
alias /usr/share/nginx/cert/data;
}
}
include /etc/nginx/conf.d/*.conf;
}