搭建nginx目录浏览功能
1 搭建nginx容器
# 下载镜像
docker pull nginx:1.23.0
# 创建容器
# 注意:如果使用"-v /home/nginx/conf.d:/etc/nginx/conf.d"共享目录,
# 则在容器中"/etc/nginx/conf.d"目录下不会生成“default.conf”文件
docker run -itd \
--name nginx_share \
-p 80:80 \
-v /home/nginx/share:/home/share \
-v /home/nginx/conf.d:/etc/nginx/conf.d \
nginx:1.23.0
default.conf文件默认内容如下
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
2 修改nginx配置文件
# 进入容器
docker exec -it nginx_share /bin/bash
# 进入”/etc/nginx/conf.d“目录
cd /etc/nginx/conf.d
# 编辑default.conf
vim default.conf
"default.conf"文件内容
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location /software {
root /home/share;
# index index.html index.htm;
# 自动目录索引
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}