Nginx部署 :
1.搜索nginx镜像
docker search nginx
2.拉取nginx镜像
docker pull nginx
3.创建目录
mkdir nginx
cd nginx
mkdir conf
cd conf
vim nginx.conf
4.编写nginx.conf配置文件
user nginx;
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;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
说明:
第四步其实可以省略,默认创建一个nginx容器,会在/etc/nginx/目录下生成一个叫nginx.conf的
配置文件,nginx容器启动会去加载该文件,该文件的内容和第四步配置文件的内容相同。这个文
件的末尾有include /etc/nginx/conf.d/*.conf;这句话,也就说在conf.d目录下并且以conf结尾的
文件都会被加载,而这个目录下只有一个配置文件就是default.conf,default.conf文件的内容配
置了一个server节点,以及默认访问nginx的目录和首页(/html/index.html)
5.创建nginx容器、端口映射、目录挂载
docker run -id --name=c_nginx \
-p 8000:80 \ #左边是对外开放的端口,右边是JAR端口
-v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ #不挂载这个配置文件也是可以的
-v /root/nginx/logs:/var/log/nginx \ #nginx容器默认的日志文件保存
到/var/log/nginx目录下
-v /root/nginx/html:/usr/share/nginx/html \ #nginx默认会去访
问/usr/share/nginx/html下的index.html
nginx
docker run -id --name=c_nginx -p 80:80 nginx
如果你不想挂载,所有的都可以不挂载,如果所有的都不挂载,默认情况,当创建nginx容器时,
在/etc/nginx/目录下有nginx.conf这个文件,这个文件是nginx的配置文件,nginx容器启动的时
候会去读这个配置文件
在宿主机的/root/nginx/html目录下新建 index.html,让其同步到/usr/share/nginx/html目录下
测试访问:http://192.168.128.130/