From Funtoo
Revision as of 23:35, May 20, 2015 by Threesixes (talk | contribs) (more details)
Jump to navigation Jump to search



We welcome improvements to this page. To edit this page, Create a Funtoo account. Then log in and then click here to edit this page. See our editing guidelines to becoming a wiki-editing pro.

Tengine is an www-servers/nginx fork. It supports DSO module loading, meaning it can have external modules without the need to compile them in. Tengine is a good back end web server node choice.


Shared & Static Modules

If you happen to want all modules installed dynamically, you, still, need to install some static modules. Make sure to add this to your /etc/portage/make.conf file:

   /etc/portage/make.conf - Tengine all-modules build
TENGINE_SHARED_MODULES_HTTP="access addition autoindex browser charset_filter empty_gif fastcgi flv footer_filter geoip image_filter limit_conn limit_req lua map memcached mp4 random_index referer reqstat rewrite scgi secure_link slice split_clients sub sysguard tfs trim_filter upstream_ip_hash upstream_least_conn upstream_session_sticky user_agent userid_filter uwsgi xslt"
TENGINE_STATIC_MODULES_HTTP="concat dav degradation geo gunzip gzip gzip_static perl proxy realip spdy ssi ssl stub_status upstream-rbtree upstream_check upstream_consistent_hash upstream_keepalive"

External Modules

Passenger is an easy method to serve ruby, python, node.js, and Meteor cms' or web applications.

If you want to run passenger:

   /etc/portage/make.conf - build the passenger module

Then merge:

root # emerge tengine


Files for configuration are located at /etc/tengine

The major differing point in tengine from nginx is that you have to specifically declare which modules are loaded. Available modules are located at /var/lib/tengine/modules.

   /etc/tengine/tengine.conf - DSO module statements
dso {
	load; ## added because you want most likely use allow & deny on certain positions


/etc/tengine/tengine.conf contains engine specific configurations.


/etc/tengine/sites-available/localhost has site specific configurations. Generally localhost is copied to domain.tld file formats in the /etc/tengine/sites-available/ directory.


These days, it is usual to have anything on https to protect your users regarding login and privacy where it comes handy to automatically redirect requests from http which are often a result of the browsers autocompletion. To achieve that, we need a server listening on http and redirecting to our main server on https like this :

   /etc/tengine/sites-available/redir - redirection from http to https
server {
        server_name domain.tld;
        listen 80;
	return 302  https://www.domain.tld$request_uri;

Unix Socket

To listen on a unix socket &

   /etc/tengine/sites-available/localhost - Listen on a unix socket
	listen unix:/var/run/tengine.sock;


Tengine does not natively support php, so we delegate that responsibility to php-fpm

   /etc/tengine/sites-available/localhost - fpm tcp/ip configuration
server {
	index index.php index.cgi index.htm index.html;
	location ~ \.php$ {
		fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
#	        fastcgi_pass;   #uncomment this line, and comment the socket line above to use tcp
		include fastcgi.conf;


Passenger's app environments:

  1. test
  2. development
  3. production

Anything the internet can touch should be in production mode.

Ruby on Rails

To serve with passenger, change the root statement below to point to your application's public directory:

   /etc/tengine/sites-available/localhost - passenger configuration
passenger_root /usr/libexec/passenger/locations.ini;
passenger_ruby /usr/bin/ruby;

server {
        passenger_enabled on;
	passenger_app_env development;
	root /home/$USER/ror/public;


   /etc/tengine/sites-available/localhost - passenger configuration
passenger_root /usr/libexec/passenger/locations.ini;
passenger_ruby /usr/bin/ruby;

server {
        passenger_enabled on;
	passenger_app_env development;
	root /home/$USER/node/public;

Create the public directory:

root # mkdir /home/$USER/node/public

Passenger's node entry point is app.js, the entry point must be named this for passenger to serve it.

Create a node hello world:

   /home/$USER/node/app.js - node hello world
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World From Node.js\n");

//**only for instances started via node app.js** Listen on port 8000, IP defaults to

//**only for instances started via node app.js** Put a friendly message on the terminal
console.log("Server running at");



This section is in need of updates.

Currently (01:52, May 19, 2015 (UTC)) python 3.x doesn't clash well with passenger, however python 2.7 runs well.

root # eselect python set  python2.7


To start the tengine server:

root # rc-update add tengine default
root # rc