mkdir /opt/nginx
#编辑docker-compose.yml文件
vim docker-compose.yml
version: '3.1'
services:
nginx:
restart: always
image: daocloud.io/library/nginx:latest
container_name: nginx
ports:
- 80:80
volumes:
- /opt/nginx/nginx.conf:/etc/nginx/nginx.conf
- /opt/nginx/html:/usr/share/nginx/html
- /opt/nginx/log:/var/log/nginx
#编辑 nginx.conf
vim nginx.conf
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
# 以上统称为全局块
# worker_processes数值越大,Nginx的并发能力就越强
# error_log表示Nginx的错误日志存放位置
events {
worker_connections 1024;
}
# events模块
# worker_connections数值越大,Nginx的并发能力就越强
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# conf.d下default.conf的内容,一个server块
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index h1.html h1.htm;
}
# location块
# root:将接收到的请求根据/usr/share/nginx/html去查找静态资源
# index:默认去上述路径中找到index.html或index.htm
}
# server块
# listen: 代表Nginx监听的端口号
# localhost: 代表Nginx接收请求的ip
include /opt/nginx/conf.d/*.conf;
}
# http块
# include表示引入一个外部的文件 --> /mime.types中存放着大量的媒体类型
# include /etc/nginx/conf.d/*.conf; --> 引入了conf.d目录下的以.conf为结尾的配置文件
~
#几个注意点
# 1。 user root 必须与你的用户名对应
# 2.nginx.conf中路径是以nginx容器的路径来写的,并不是宿主机路径
#编写html
vim /opt/nginx/html/h1.html
<h1>!!!!hi nginx !!!</h1>
~
03-16
3810
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-05
1560
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
393
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)