Tengine is a web server originated by Taobao, the largest e-commerce website in Asia. It is based on the Nginx HTTP server and has many advanced features. Tengine has proven to be very stable and efficient on some of the top 100 websites in the world, including taobao.com and tmall.com.
Tengine has been an open source project since December 2011. It is being actively developed by the Tengine team, whose core members are from Taobao, Sogou and other Internet companies. Tengine is a community effort and everyone is encouraged to get involved.
- All features of nginx-1.6.2 are inherited, i.e., it is 100% compatible with nginx.
- Dynamic module loading support. You don't need to recompile Tengine when adding new modules to it.
- SPDY v3 support, and SPDY/HTTP servers can listen on the same port.
- Sends unbuffered upload directly to HTTP and FastCGI backend servers, which saves disk I/Os.
- More load balancing methods, e.g., consistent hashing, and session persistence.
- Input body filter support. It's quite handy to write Web Application Firewalls using this mechanism.
- Dynamic scripting language (Lua) support, which is very efficient and makes it easy to extend core functionalities.
- Logging enhancements. Syslog (local and remote), pipe logging, and log sampling are supported.
- Limits retries for upstream servers (proxy, memcached, fastcgi, scgi, uwsgi).
- Includes a mechanism to support standalone processes.
- Protects the server in case system load or memory use goes too high.
- Removes unnecessary white spaces and comments to reduce the size of a page.
- Proactive health checks of upstream servers can be performed.
- The number of worker processes and CPU affinities can be set automatically.
- The limit_req module is enhanced with whitelist support and more conditions are allowed in a single location.
- Enhanced diagnostic information makes it easier to troubleshoot errors.
- More user-friendly command lines, e.g., showing all compiled-in modules and supported directives.
- Expiration times can be specified for certain MIME types.
- Error pages can be reset to 'default'.
How to use this image
hosting some simple static content
$ docker run --name nginx -v /some/content:/usr/local/nginx/html:ro -d chasontang/tengine:2.1.2_f
Alternatively, a simple
Dockerfile can be used to generate a new image that includes the necessary content (which is a much cleaner solution than the bind mount above):
FROM chasontang/tengine:2.1.2_f COPY static-html-directory /usr/local/nginx/html
Place this file in the same directory as your directory of content ("static-html-directory"), run
docker build -t some-content-nginx ., then start your container:
$ docker run --name nginx -d some-content-nginx
exposing the port
$ docker run --name nginx -d -p 8080:80 some-content-nginx
Then you can hit
http://host-ip:8080 in your browser.
$ docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d chsontang/tengine:2.1.2_f
Be sure to include
daemon off; in your custom configuration to ensure that Nginx stays in the foreground so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
If you wish to adapt the default configuration, use something like the following to copy it from a running Nginx container:
$ docker cp some-nginx:/etc/nginx/nginx.conf /some/nginx.conf
As above, this can also be accomplished more cleanly using a simple
FROM chasontang/tengine:2.1.2_f COPY nginx.conf /etc/nginx/nginx.conf
Then, build with
docker build -t some-custom-nginx . and run:
$ docker run --name some-nginx -d some-custom-nginx
using environment variables in nginx configuration
Out-of-the-box, Nginx doesn't support using environment variables inside most configuration blocks. But
envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.
Here is an example using docker-compose.yml:
image: chasontang/tengine:2.1.2_f volumes: - ./mysite.template:/etc/nginx/conf.d/mysite.template ports: - "8080:80" environment: - NGINX_HOST=foobar.com - NGINX_PORT=80 command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
mysite.template file may then contain variable references like this :