当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
23 Star 42 Fork 11

xiaozhuai / efserv
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

efserv

[中文文档] [English README]

efserv 是一个事件驱动异步模型的http静态文件服务器,使用C++编写。具有高性能,低内存的优点。全名为 EzFileServer。

由于是一个静态文件服务器,所有的请求都会被当做 GET 请求来处理。

logo

依赖

在构建项目之前,你需要安装 libevlibeio

libeio

$ git clone https://github.com/xiaozhuai/libeio
$ cd libeio
$ ./autogen.sh
$ ./configure
$ make
$ make install # maybe with sudo

libev

Debian 系列 linux:

$ sudo apt-get install libev-dev

Redhat 系列 linux:

我没有尝试,你可以自己google一下。或者从源码编译也是个不错的选择。

For OSX:

你需要安装brew。(一个osx平台的包管理软件)

$ brew install libev

构建

efserv 使用 cmake 来构建项目。

参考下面的步骤

$ cd /path/to/efserv
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Debug # or Release
$ make
$ make install

将会安装这些文件:

-- Installing: /usr/local/bin/efserv
-- Installing: /usr/local/efserv/tpl
-- Installing: /usr/local/efserv/tpl/dir_indexs.html
-- Installing: /usr/local/efserv/tpl/err.html
-- Installing: /usr/local/efserv/README.md
-- Installing: /usr/local/efserv/README_CN.md
-- Installing: /usr/local/efserv/LICENSE.md
-- Installing: /usr/local/efserv/.efserv_access
-- Installing: /usr/local/efserv/config.ini
  • /usr/local/bin/efserv 二进制可执行文件
  • /usr/local/efserv/tpl efserv使用的视图模板文件
  • /usr/local/efserv/.efserv_access 一个访问控制配置的demo文件
  • /usr/local/efserv/config.ini 一个服务配置的demo文件

运行

至今执行命令 efserv 就可以了。 /var/www 将会是默认的web根目录。

你可以更改这些选项,执行 efserv --help 来获取帮助。

EzFileServer
Author : xiaozhuai
Email  : 798047000@qq.com
Usage  : efserv [OPTION]...

All arguments are long options
  --config <file>           Define the ini config path, it will be ".efserv_config" under web root by default
  --root <dir>              Define the web root path, it will be "/var/www" by default
  --log-level <level>       Define the log level, available levels are : disable, error, warning, info(default), debug
  --deamon                  Run as deamonize mode
  --help                    Print this help message

选项

使用 --root 选项来定义web根目录

使用 --config 选项来定义服务配置文件的路径。

如果你运行时没有提供 --config 选项, efserv 将会在web根目录下寻找名为 .efserv_config 的文件作为配置文件. 如果不存在这个文件,将会使用内置的默认值。

efserv 有5个日志等级, 你可以通过 --log-level 选项来调节。

如果你想要用守护进程方式运行,使用 --deamon 选项。

配置

让我们来看一下配置文件里都有些什么。

查看 /usr/local/efserv/config.ini (这只是一个demo)

文件里已经包含详细的说明。

# EzFileServer project
# author: xiaozhuai
# email: 798047000@qq.com

# define the listening addr, use 0.0.0.0 by default
#listen = 0.0.0.0

# define the listening port, use 80 by default
port = 8080

# whether enable dir indexs, is enabled by default, 0 disable, 1 enable
# if disable, all request to dir will be denied (403)
# dir_indexs = 1

# define the view tpl of dir indexs, use "/usr/local/efserv/tpl/dir_indexs.html" by default
# dir_indexs_tpl = /usr/local/efserv/tpl/dir_indexs.html
# dir_indexs_tpl = tpl/dir_indexs.html

# define the err page tpl, use "/use/local/efserv/tpl/err.html" by default
# err_tpl = /use/local/efserv/tpl/err.html
# err_tpl = tpl/err.html

# define the access rule file name, use ".efserv_access" by default. This file should be under the root of web server
# .efserv_access should be like this
# - ^/private/.*$
# + ^/private/resources/.*$
# all request start with "/private/" will be denied, except the request start with "/private/resources/"
# warning!
# if change it to
# + ^/private/resources/.*$
# - ^/private/.*$
# things will be different, all request start with "/private/" will be denied
# the rule are matched from up to bottom, the last rule will be effective
# if nothing is private, just remove this file or let it empty
# by default, ".efserv_access" itself and ".efserv_config" in web root is denied, you can allow it by add line "+ .efserv_access" and "+ .efserv_config"
# access_rule = .efserv_access

访问控制

在配置文件中,我们发现一个配置项为 access_rule,这个文件包含了访问控制的规则,匹配规则使用正则匹配。

默认情况下,访问控制文件位于web根目录下,名为 .efserv_access ,你可以在配置文件中修改默认的文件名, 但是你必须把它放到web根目录下。

查看 /usr/local/efserv/.efserv_access

# Denied private
- /private # in-line comment
+ /test
+ /demo

+ 意为允许 - 意为禁止

使用正则,例如

+ ^/private/resources/.*$
- ^/private/.*$

Issues

如果发生 addr bind error 错误,可能该端口已经被其它程序占用,或者选择的端口小于1024。 小于1024的端口是系统保留的,如果需要使用小于1024的端口,必须提供root用户权限,使用 sudo efserv ...。 这不是一个issue。

图片

Indexs

File

403

404

MIT License Copyright (c) 2017 xiaozhuai, Weihang Ding Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

efserv是一个事件驱动的使用c++编写的高性能http静态文件服务器,全名为EzFileServer 展开 收起
C++
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/xiaozhuai/efserv.git
git@gitee.com:xiaozhuai/efserv.git
xiaozhuai
efserv
efserv
master

搜索帮助

14c37bed 8189591 565d56ea 8189591