使用docker-compose部署nginx以后使用在网页访问403错误
我的docker-compose内容如下:
[root@localhost compose-nginx]# cat docker-compose.yaml
version: "2.16.0"
services:
nginx:
hostname: nginx
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- "1216:80"
- "1217:443"
networks:
- cluster
volumes:
- ./wwwroot/:/usr/local/nginx/html
networks:
cluster:
假设在docker-compose.yaml文件中定义了一个名为nginx的服务且服务正在运行,可以用以下命令进入该容器:
docker-compose exec nginx bash
查找报错日志
find / -name error.log
报错如下
[root@nginx var]# cat /usr/local/nginx/logs/error.log
2024/04/02 04:18:54 [error] 8#0: *1 directory index of "/usr/local/nginx/html/" is forbidden, client: 192.168.25.1, server: localhost, request: "GET / HTTP/1.1", host: "192.168.25.131:1216" 2024/04/02 04:18:55 [error] 8#0: *1 directory index of "/usr/local/nginx/html/" is forbidden, client: 192.168.25.1, server: localhost, request: "GET / HTTP/1.1", host: "192.168.25.131:1216"
这条日志信息显示的是 Nginx 在尝试提供目录列表时遇到的问题。错误消息指出,Nginx 禁止了 /usr/local/nginx/html/
目录的索引(即不允许列出目录内容)。这通常是因为 Nginx 的配置中没有启用目录列表功能,或者该目录中没有默认的索引文件(如 index.html
或 index.php
)
使用find查找index.html文件复制到 /usr/local/nginx/html/