Main  /  Edit version 8  /  Edit version 9  /   /  Users Area

Difference "Configure CppCMS to run with different web servers" ver. 8 versus ver. 9

Content:

<!--toc-->
## Introduction
There are many options to connect CppCMS application to web server:
- Select protocol: you can use FastCGI or SCGI protocols,
you can also run over HTTP protocol behind proxy.
Recommendation: use FastCGI as it has best support
over various web servers.
- Application start: it can be started by the web server
and controlled by it or it can run as independent
service when web server only connects to it.
- Communication method: you can use Unix domain sockets
or tcp/ip sockets. For local communication unix sockets
are preferred.
## Assumptions
In all our examples we assume:
- Application's executable placed in `/opt/app/bin/hello`
- Application's configuration file placed in `/opt/app/etc/config.js`
- The document root is `/var/www`
- Our application's URL (script) is `/hello`
## Apache
### Apache, FastCGI
You need to enable at least two modules: `mod_fastcgi` and `mod_alias`
For each case we prepare `mod_fastcgi` configuration file
and out config.js
#### Apache, FastCGI, Start by Web Server
Apache configuration:
FastCgiIpcDir /var/lib/apache2/fastcgi
# Usually it is given in fastcgi.conf by default
FastCgiServer /opt/app/bin/hello -initial-env CPPCMS_CONFIG=/opt/app/etc/config.js -socket /tmp/hello-fcgi-socket
# CPPCMS_CONFIG should hold the path to configuration file.
# Note: you can't pass command line parameter
# so you pass the location of configuration file
# via CPPCMS_CONFIG environment variable
FastCGIConfig -maxProcesses 1 -processSlack 1
# This is important - we want apache to use only
# one process as we have cache and many other
# goodies handled by outsefs
ScriptAliasMatch ^/hello(.*)$ /opt/app/bin/hello$1
# We map script "/hello" to our application
AddHandler fastcgi-script /opt/app/bin/hello
CppCMS configuration:
{
"service" : {
"api" : "fastcgi",
"socket": "stdin" // we use socket given by server
}
}
#### Apache, FastCGI, Independent start
Apache configuration:
FastCgiIpcDir /var/lib/apache2/fastcgi
# Usually it is given in fastcgi.conf by default
FastCgiExternalServer /opt/app/bin/hello -socket /tmp/hello-fcgi-socket
# We provide a socket the application listens on.
ScriptAliasMatch ^/hello(.*)$ /opt/app/bin/hello$1
# We map script "/hello" to our application
AddHandler fastcgi-script /opt/app/bin/hello
CppCMS configuration:
{
"service" : {
"api" : "fastcgi",
"socket": "/tmp/hello-fcgi-socket"
// Same as in apache config
}
}
Now you should run the CppCMS application independently
as `/opt/app/bin/hello -c /opt/app/etc/config.js`
If you want to use TCP/IP sockets and not Unix one change
- in `FastCgiExternalServer` line parameter `-socket` to `-host 127.0.0.1:8081`
- in CppCMS config change `"socket": "/tmp/hello-fcgi-socket"` to `"host" : "127.0.0.1", "port" : 8081`
### Apache, SCGI
Apache's `mod_scgi` supports only in-depended/external start and works over TCP/IP sockets, so the configuration is quite simple:
Apache's module configuration:
SCGIMount /hello 127.0.0.1:8081
We pass the script name as mount point and ip:port as
point to connect cppcms application.
CppCMS configuration:
{
"service" : {
"api" : "scgi",
"host" : "127.0.0.1",
"port" : 8081
}
}
Now you should run the CppCMS application independently
as `/opt/app/bin/hello -c /opt/app/etc/config.js` and Apache would connect to it.
## Lighttpd
Lighttpd supports both fastcgi/scgi protocols over unix and tcp/ip sockets. It can start the application for you and use external FastCGI/SCGI application.
### Lighttpd, FastCGI
#### Lighttpd, FastCGI, Start by Web Server
You should enable mod-fastcgi and then use this Configuration file:
fastcgi.server = (
## The script name of the application
"/hello" => ((
## Command line to run
"bin-path" => "/opt/app/bin/hello -c /opt/app/etc/config.js",
"socket" => "/tmp/hello-fcgi-socket",
## Important - only one process should start
"max-procs" => 1,
"check-local" => "disable"
))
)
CppCMS configuration:
{
"service" : {
"api" : "fastcgi",
"socket" : "stdin" // use server's socket
}
}
#### Lighttpd, FastCGI, External Start
You should enable mod-scgi and then use this Configuration file:
fastcgi.server = (
## The script name of the application
"/hello" => ((
"socket" => "/tmp/hello-fastcgi-socket",
## Important - only one process should start
"max-procs" => 1,
"check-local" => "disable"
))
)
CppCMS configuration:
{
"service" : {
"api" : "fastcgi",
"socket" : "/tmp/hello-fastcgi-socket" // use server's socket
}
}
If you want to use TCP/IP rather then Unix sockets, replace
- In lighttpd configuration: `"socket" => "/tmp/hello-scgi-socket",` by `"host" => "127.0.0.1", "port" => 8081,`
- In cppcms configuration: `"socket" : "/tmp/hello-scgi-socket"`, by `"host": "127.0.0.1" , "port" : 8081,`
- In lighttpd configuration: `"socket" => "/tmp/hello-fastcgi-socket",` by `"host" => "127.0.0.1", "port" => 8081,`
- In cppcms configuration: `"socket" : "/tmp/hello-fastcgi-socket"`, by `"host": "127.0.0.1" , "port" : 8081,`
### Lighttpd, SCGI
#### Lighttpd, SCGI, Start by Web Server (lighttpd >=1.4.23)
You should enable mod-scgi and then use this Configuration file:
scgi.server = (
## The script name of the application
"/hello" => ((
## Command line to run
"bin-path" => "/opt/app/bin/hello -c /opt/app/etc/config.js",
"socket" => "/tmp/hello-fcgi-socket",
## Important - only one process should start
"max-procs" => 1,
"check-local" => "disable"
))
)
CppCMS configuration:
{
"service" : {
"api" : "scgi",
"socket" : "stdin" // use server's socket
}
}
#### Lighttpd, SCGI, External Start
You should enable mod-scgi and then use this Configuration file:
scgi.server = (
## The script name of the application
"/hello" => ((
"socket" => "/tmp/hello-scgi-socket",
## Important - only one process should start
"max-procs" => 1,
"check-local" => "disable"
))
)
CppCMS configuration:
{
"service" : {
"api" : "scgi",
"socket" : "/tmp/hello-scgi-socket" // use server's socket
}
}
If you want to use TCP/IP rather then Unix sockets, replace
- In lighttpd configuration: `"socket" => "/tmp/hello-scgi-socket",` by `"host" => "127.0.0.1", "port" => 8081,`
- In cppcms configuration: `"socket" : "/tmp/hello-scgi-socket"`, by `"host": "127.0.0.1" , "port" : 8081,`

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0