根据视频学习nginx(https://www.bilibili.com/video/BV1W54y1z7GM?p=5)
1.安装nginx
- linux虚拟机里创建一个nginx文件夹并进入
- 创建一个docker-compose.yml文件,里面添加内容,不能用tab键加空格
version: '3.1'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf.d:/etc/nginx/conf.d
- 接着创建一个conf.d文件夹并进入,然后创建一个default.conf文件,在里面添加内容
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
- 返回创建的yml文件那一层使用docker-compose命令创建容器
docker-compose up -d
- 使用本机输入虚拟机地址即可访问