准备条件 : Ubuntu服务器 和 Docker 和docker-compose
使用 cd /usr/local
进入该目录下,使用 mkdir docker
创建docker目录然后进入。
使用vi docker compose.yml
创建nginx
version 版本要和docker 版本匹配
version: '3.7'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 81:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./wwwroot:/usr/share/nginx/wwwroot
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511103147290-559580309.png)
然后使用mkdir conf
创建conf目录并进入。
使用vi nginx.conf
创建nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_header_buffer_size 2k;
server {
listen 80;
server_name 192.168.227.129;
location / {
root /usr/share/nginx/wwwroot/html80;
index index.html index.htm;
}
}
}
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511104755851-1999922303.png)
然后退回到上级目录,使用docker-compose up -d
以守护态开启nginx.
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511103227144-770539880.png)
使用docker ps
查看
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511103254594-399816433.png)
进入wwwroot目录,使用mkdir html80
创建html80目录,进入该目录,
使用vi index.html
创建index.html页面,写入内容 :Hello Nginx!!
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511104221068-2103978839.png)
![](https://img2018.cnblogs.com/blog/1234831/201905/1234831-20190511104500714-555392371.png)