Docker运行nginx文件服务器详细配置

Nginx.conf

user  root;
worker_processes  1;

error_log  /var/log/Nginx/error.log warn;
pid        /var/run/Nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/Nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/Nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/Nginx/conf.d/*.conf;
}

Nginx启动用户修改为root,否则会存在文件权限问题

 

Nginx-file-server.conf

server {
    listen 8081; #端口
    server_name localhost; #服务名
    charset utf-8; # 避免中文乱码
    root /data; #显示的根索引目录,注意这里要改成你自己的,目录要存在

    location / {
        autoindex on;             #开启索引功能
        autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
        autoindex_localtime on;   # 显示本机时间而非 GMT 时间
    }
}

启用8081作为文件服务器端口

 

运行命令:

docker run -d -p 8081:8081 --name file-server -v $(pwd):/data -v $(pwd)/Nginx.conf:/etc/Nginx/Nginx.conf -v $(pwd)/Nginx-file-server.conf:/etc/Nginx/conf.d/Nginx-file-server.conf Nginx

命令将宿主的当前目录挂载到容器的/data目录,并挂载conf配置文件,启动Nginx

 

或者直接运行以下命令

curl -s https://files-cdn.cnblogs.com/files/nihaorz/start-Nginx-file-server.sh | bash

 

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...