1、创建一个nginx配置文件/etc/nginx/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 mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on; # 开启目录列表
location / {
try_files $uri $uri/ =404;
}
}
}
请确保 server
指令在 http
块内。其中 autoindex on; # 开启目录列表
2、运行docker的nginx把配置文件映射到容器内部
docker run --name retrievl_nginx -d \
-v /path/to/your/nginx.conf:/etc/nginx/nginx.conf \
-v /path/to/files:/usr/share/nginx/html \
-p 9993:80 \
nginx
这里的 /path/to/your/nginx.conf
是你修改后的配置文件路径。
3、重启 Nginx 容器:
docker restart retrievl_nginx
4、浏览器访问,服务器ip:9993