docker nginx 文件服务器

abdulla1992
2023-01-16 / 0 评论 / 122 阅读 / 正在检测是否收录...
sudo docker stop ab-nginx
sudo docker rm ab-nginx

sudo docker run -d -p 6068:6068 \
        --name ab-nginx \
        -v $(pwd)/data:/data \
        -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf \
        -v $(pwd)/default.conf:/etc/nginx/conf.d/default.conf \
        -v $(pwd)/nginx-passwd:/nginx-passwd \
        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;
    server_tokens off;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

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

default.conf

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

    location / {
        autoindex on;             #开启索引功能
        autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
        autoindex_localtime on;   # 显示本机时间而非 GMT 时间
        auth_basic "closed site";
        # 用户、密码文件存放路径
        auth_basic_user_file nginx-passwd;
    }
}
0

评论 (0)

取消