美文网首页
使用 Nginx 作为 HTTP 文件服务

使用 Nginx 作为 HTTP 文件服务

作者: AlphaHinex | 来源:发表于2020-05-08 18:37 被阅读0次

原文地址:https://alphahinex.github.io/2020/05/08/use-nginx-as-file-server/

cover

description: "Http 访问,中文路径及基本权限控制"
date: 2020.05.08 19:34
categories:
- Nginx
tags: [Nginx, HTTP]
keywords: Nginx, File server, HTTP, Charset, Basic HTTP authentication, ngx_http_auth_basic_module


伺服文件路径

ngx_http_autoindex_module 模块可处理请求并生成目录列表。启用后当 ngx_http_index_module 模块无法找到 index 文件时,会将请求交给 ngx_http_autoindex_module 模块处理。

配置示例:

location / {
    autoindex on;
}

其他相关指令可查看 官方文档

另外,需要配合 ngx_http_core_module 模块的 root 指令指定文件服务的根路径,如:

location /i/ {
    root /data/w3;
}

设定字符集

ngx_http_charset_module 提供了 charset 指令,设定相应字符集可以解决中文乱码问题,如:

location / {
    charset utf-8;
}

添加基本访问权限控制

ngx_http_auth_basic_module 提供了使用 “HTTP Basic Authentication” 协议,进行基本的用户名和密码的认证。

配置示例:

location / {
    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}

auth_basic 可以是任意字符串;auth_basic_user_file 需指定一个包含用户名和密码的文件,文件格式如下:

# comment
name1:password1
name2:password2:comment
name3:password3

密码可使用 openssl passwd 命令生成,例如:

$ openssl passwd -crypt 123456
AvkEiRVc9LrPs

注意:相同密码每次生成的密文不一致

更多支持的密码类型,可见 模块文档

完整实例

nginx 配置:https://github.com/AlphaHinex/compose-docker/blob/master/nginx/file_server.conf

可借助 docker-compose 启动:

$ docker-compose up -d nginx

之后访问 http://localhost:2020

输入用户名 alpha,密码 hinex,即可看到文件列表。

相关文章

  • 使用 Nginx 作为 HTTP 文件服务

    原文地址:https://alphahinex.github.io/2020/05/08/use-nginx-as...

  • fastdfs启动与停止详解

    文件上传成功,需要安装Nginx作为服务器以支持Http方式访问文件。同时,后面安装FastDFS的Nginx模块...

  • 10.Nginx作为静态资源WEB服务-配置语法(sendfil

    静态资源WEB服务 Nginx作为静态资源WEB服务 , Nginx作为静态资源的HTTP WebServer它可...

  • 环境部署

    概述 服务器的操作系统是Ubuntu14.04(64位),使用Nginx作为反向代理,uWSGI作为HTTP服务器...

  • nginx代理功能与负载均衡

    一:nginx功能:Nginx功能丰富,可作为HTTP服务器,也可作为反向代理服务器,邮件服务器。支持FastCG...

  • 利用Nginx+Subversion搭建SVN http协议服务

    大概步骤 搭建svn服务 使用Apache HTTP服务将svn协议转成http协议 nginx转发http请求到...

  • nginx

    node 使用 nginx 反向代理搭建https服务 使用自己生成的证书 nginx http配置 编辑ngin...

  • PHP 运行模式

    web 服务器 一般情况下,服务器使用 Nginx、Apache、IIS 等作为 Http 服务端,处理客户端的连...

  • Nginx--keepalive 的配置

    nginx 作为反向代理服务器中的 keepalive 在 nginx 中, 对于 http1.0 和 http1...

  • Nginx-Keepalive

    在我们选在Nginx作为http请求的负载均衡时候,整个请求的流向是:上游服务 --> Nginx -->下游服务...

网友评论

      本文标题:使用 Nginx 作为 HTTP 文件服务

      本文链接:https://www.haomeiwen.com/subject/dunkghtx.html