<!--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` |
|
## Apache2 |
|
### Apache2, 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 |
|
#### Apache2, 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. |
|
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 |
} |
} |
|
#### Apache2, FastCGI, Independent start |
|
Apache configuration: |
|
|
FastCgiIpcDir /var/lib/apache2/fastcgi |
# Usually it is given in fastcgi.conf by default |
|
FastExternalCgiServer /opt/app/bin/hello -socket /tmp/hello-fcgi-socket |
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 |
} |
} |
|
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` |
|