Watch 23 Star 39 Fork 8

xiaozhuai / efservC++MIT

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
efserv是一个事件驱动的使用c++编写的高性能http静态文件服务器,全名为EzFileServer spread retract

Clone or download


[中文文档] [English README]

efserv is an Event-driven asynchronous http static file server written in C++,high performance,and low memory. Full name is EzFileServer.

Since it's a file server, all http request will be treated as GET



Before you can build, you need install libev and libeio.


$ git clone
$ cd libeio
$ ./
$ ./configure
$ make
$ make install # maybe with sudo


For linux (debian like):

$ sudo apt-get install libev-dev

For linux (redhat like):

Sorry, I do not try it, find out yourself. Or build from sources is fine.

For OSX:

You need brew. (A package manager for osx)

$ brew install libev


efserv use cmake for building.

Follow these steps:

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

These things will be installed:

-- 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/
-- Installing: /usr/local/efserv/
-- Installing: /usr/local/efserv/
-- Installing: /usr/local/efserv/.efserv_access
-- Installing: /usr/local/efserv/config.ini
  • /usr/local/bin/efserv is the program binary
  • /usr/local/efserv/tpl are the tpls used when err occured or dir indexs
  • /usr/local/efserv/.efserv_access is a demo of access rules config
  • /usr/local/efserv/config.ini is a demo of server config


Just exec command efserv. /var/www will be the default web root directory.

Yes, you can change it, just typing efserv --help to get help.

Author : xiaozhuai
Email  :
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


Use --root option to define the web root.

And you can define a config file on command line provide --config option with params.

If you do not provided the --config option, efserv will find config file in web root which named .efserv_config. If not exist, it will use its default values.

efserv has 5 log-level, and you can define it before runing use --log-level option.

If you want run as deamonize mode, --deamon option provided.


Let's find out what are there in config file.

Take a look at /usr/local/efserv/config.ini(this is just a demo file).

# EzFileServer project
# author: xiaozhuai
# email:

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

# 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

In config file, we see an option named access_rule, this file contains access rule, by regex matching.

This file is under web root directory named .efserv_access by default, you can change its name in config file, but you should always put it under web root directory.

Look at /usr/local/efserv/.efserv_access

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

+ means allow - means denied.

And regex pattern is fine, for example

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


If addr bind error occured, maybe port is in use, or port < 1024, you know, if port < 1024, you need root user authority, just run with sudo efserv .... This not an issue.






Comments ( 7 )

Sign in for post a comment



231008 48f1a665 1899542 231017 9a6720c6 1899542