Quick Nav
- Built-in Web Server
- Hosted Web Server
- CGI
- FastCGI
- In-memory Modules
- Supported Web Servers
- Configuring Apache
- Configuring Appweb
- Configuring Lighttpd
See Also
Web Framework Hosting in Web Servers
WARNING: This document is is under construction and the instructions herein have not been fully tested.
Ejscript includes a web server for easy development and deployment. You can use this built-in web server, or you can configure Ejscript to run in a supported web server of your choosing.
Built-in Web Server
The easiest way to run Ejscript applications is to use the builtin web-server.
ejsweb run appweb: 1: Starting host named: "127.0.0.1:4000" appweb: 1: HTTP services are ready (single-threaded)
The ejsweb run command will run the web server and your application. This assumes you have already created the application and invoke this command the application's top directory. Please read the Web Framework Tour for steps to create a new application.
Once running, you can then enter the application URL in our browser. The URL will be of the form:
http://localhost:4000
Configuring the Built-in Web Server
The built-in web server is based on the Appweb high-performance embedded web server coupled with an in-memory module for Ejscript. You can modify the Appweb command via your Application's config/config.ecf configuration file. The webserver configuration property defines the command line used to start Appweb.
app: { webserver: "ejswebserver --ejs /app/:/var/www/app/ --log /dev/tty:2" },
You can vary the verbosy of trace to the console level by chaning the log level. Zero disables, two is quiet and displays important errors. Level four will trace all requests.
Please see the Configuring Appweb guide for more details about configuring Appweb.
Hosting Ejscript in a Web Server
To run the Ejscript Web Framework, it must be hosted by a Web Server. The web server receives client requests and dispatches requests to Ejscript using one of three hosting alternatives:
- CGI — via the ejscgi program.
- FastCGI — via the ejsfast program.
- Custom in-memory module — via the mod_ejs loadable module.

CGI
The Common Gateway Interface (CGI) is a standard protocol for hosting applications in a web server. CGI offers good stability but low performance. It is a reliable lowest common denominator that will run on most web servers. The ejscgi program is a CGI conformant program which hosts the Ejscript Web Framework.
FastCGI
FastCGI is a replacement for CGI. It provides higher performance than CGI by supporting multiple Http requests per FastCGI instance. It also offers improved stability by isolating application instances. The ejsfast program is a FastCGI conformant program which hosts the Ejscript Web Framework.
In-memory Modules
Custom in-memory modules offer the highest performance. Ejscript provides modules for Appweb and Apache. The custom module, mod_ejs, provides excellent performance but less application isolation.
Reverse Proxy
You can also use Ejscript hosted via an in-memory module running behind a reverse proxy. This offers the best of both worlds: performance and scalability. The recommended solution is to use mod_ejs with Appweb running behind Apache as a reverse proxy.

Supported Web Servers
To configure these hosting options, please consult the instructions specific to each supported web server below.
Configuring Apache or Appweb
Apache and Appweb have similar configuration file formats and directives and so the setup steps are the same.
Apache/Appweb can be used with the following hosting alternatives:
-
In-memory Module
The in-memory module is a loadable extension called mod_ejs. It runs inside the Apache/Appweb process and offers significant performance advantages:
- By running in-process, there are no new processes that must be started to service incoming requests.
- Ejscript creates a master interpreter which is quickly cloned for incoming requests. The master interpreter provides and initializes the core system types, so that subsequent requests start and are serviced more quickly. Memory footprint on heavily loaded sites is greatly reduced.
To configure mod_ejs in Apache/Appweb, include the following directives in the Apache/Appweb config file:
LoadModule ejsHandler /usr/lib/ejs/mod_ejs.so AddHandler ejs .ejs EjsAppAlias /myApp/ /var/www/myApp
You may need to modify the mod_ejs path or file extension to suit your system.
This example will configure Ejscript for an Ejscript web application called myApp that is located at "/var/www/myApp". The AddHandler directive will ensure that the Ejscript ejs handler is invoked for any requests that have .ejs extensions. The EjsAppAlias directive associates a URL prefix with the directory containing the application. This instructs the Apache/Appweb to send all requests with the URL prefix "/myApp/" to Ejscript for processing. For each application you wish to host, add an EjsAppAlias directive.
If you have many Ejscript applications, you can specify a directory that will contain Ejscript applications by using the EjsAppDir directive. In this manner, you don't need a per-application EjsAppAlias directive.
EjsAppDir /var/www/ejsapps
If you want to be able to access your application without the URL prefix "/myApp" and use a VirtualHost instead, use the following directives:
<VirtualHost *:80> ServerName mycorp DocumentRoot /var/www/myApp EjsApp on SetHandler ejsHandler </VirtualHost>
With this example, you can brows using the URL: "http://mycorp/".
Other mod_ejs Directives
The in-memory modules for Ejscript supports three other directives:
EjsErrors browser EjsPath SEARCH_PATH EjsSession on EjsSessionTimeout 1800
The EjsErrors directive controls whether application and framework errors are sent to the browser or sent to the web server error log. Set to "browser" or "log" respectively. The default is "browser".
The EjsPath directives sets the Ejscript module search path. The supplied path should be a ":" separated list of paths (";" on windows).
The EjsSession directive controls whether sessions (via cookies) are automatically created. If this is disabled via "off", then the Ejscript Controller will need to manually control sessions via the Controller createSession method. The EjsSessionTimeout directive defines the default session timeout in seconds.
Running Stand-Alone Ejscript Pages
To run stand-alone Ejscript web pages that are not part of a Model-View-Controller web application, define a Location block and enable the Ejscript handler.
<Location /ejs/> SetHandler ejsHandler </Location>
This will cause all URLs that begin with /ejs/ to be sent to the Ejscript handler. The Alias directive can also be used to associate a URL prefix with a specific file directory.
-
Reverse Proxy
To configure Apache to be a reverse proxy in front of Appweb, add a VirtualHost directive to the Apache configuration file (httpd.conf).
Listen 7000 <VirtualHost *:7000> ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:4000/ ProxyPassReverse / http://localhost:4000/ </VirtualHost>
This example passes requests to Apache on port 7000 to Appweb listening on 4000. Then ensure that Appweb has the appropriate EjsAppAlias or EjsAppDirAlias directive configured to respond to requests.
-
Apache with FastCGI
Coming Soon ...
-
Apache with CGI
To configure Apache to support Ejscript via CGI, you need to add a Virtual Host or Named Virtual Host to define the application directory. Then add a ScriptAlias directive to enable CGI processing.
Listen 3000 <VirtualHost *:3000> DocumentRoot /var/www/myApp <Directory "/usr/lib/ejs/webbin/"> AllowOverride None Order allow,deny Allow from all </Directory> ScriptAlias /cgi/ "/usr/lib/ejs/webbin/" </VirtualHost>
This defines an Ejscript application called myApp that will reside at the "/var/www/myApp" directory. The ejscgi program is located at "/usr/lib/ejs/webbin/ejscgi".
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.my_test_app.com DocumentRoot /Users/mob/hg/test_app <Directory "/usr/lib/ejs/webbin/"> AllowOverride None Order allow,deny Allow from all </Directory> ScriptAlias /cgi/ "/usr/lib/ejs/webbin" </VirtualHost>
Configuring Lighttpd
Lighttpd can run Ejscript using either CGI or FastCGI. However, it is best run with FastCGI.
Here are the steps to configure FastCGI on lighttpd for Ejscript. Edit the Lighttpd configuration:
-
Enable the FastCGI modules.
server.modules = ("mod_fastcgi")
-
Setup to run the FastCGI process.
fastcgi.server = (".fcgi" => ( "ejscript" => ( "min-procs" => 1, "max-procs" => 5, "socket" => "/tmp/ejscript.fastcgi", "bin-path" => "/usr/bin/ejsfast" ) ))
See the Lighttpd FastCGI documentation for further details.
Stand-Alone Ejscript Pages
Add the following directive if you want to run Ejscript for all files with an .ejs extension.
fastcgi.server = ( ".ejs" => (( "host" => "127.0.0.1", "port" => 1026, "bin-path" => "/usr/bin/ejsfast" )) )
This will configure Ejscript to receive requests begining with /ejs/.
fastcgi.server = ( "/ejs/" => (( "host" => "127.0.0.1", "port" => 1026, "bin-path" => "/usr/bin/ejsfast" )) )