README.apache_frontend.rst 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
apache_frontend
===============

Frontend system using Apache, allowing to rewrite and proxy URLs like
myinstance.myfrontenddomainname.com to real IP/URL of myinstance.

apache_frontend works using the master instance / slave instance design.
It means that a single main instance of Apache will be used to act as frontend
for many slaves.

11 12 13 14 15 16 17
Software type
=============

Apache frontend is available in 3 software types:
  * default : The standard way to use the apache frontend configuring everything with a few given parameters
  * custom-personal : This software type allow each slave to edit its apache configuration file
  * custom-group : This software type use a template given as a parameter on master instance to generate apache configuration for all slaves
18 19 20 21 22
  * replicate : This software type is set to replicate any kind of apache

About replicate frontend
========================

23
Slaves of the root instance (type "replicate") are sent as a parameter to requested frontends which will process them. The only difference is that they will then return the « would-be published information » to the root instance instead of publishing it. The root instance will then do a synthesis and publish the information to its slaves. The replicate instance only use 5 type of parameters for itself and will transmit the rest to requested frontends.
24 25 26
These parameters are :
  * "-frontend-type" : the type to deploy frontends with. (default to 2)
  * "-frontend-quantity" : The quantity of frontends to request (default to "default")
27
  * "-frontend-i-state": The state of frontend i
28
  * "-frontend-config-i-foo": Frontend i will be requested with parameter foo
29
  * "-frontend-software-release-url": Software release to be used for frontends, default to the current software release
30 31 32 33
  * "-sla-i-foo" : where "i" is the number of the concerned frontend (between 1 and "-frontend-quantity") and "foo" a sla parameter.
ex:
<parameter id="-frontend-quantity">3</parameter>
<parameter id="-frontend-type">custom-personal</parameter>
34
<parameter id="-frontend-2-state">stopped</parameter>
35
<parameter id="-sla-3-computer_guid">COMP-1234</parameter>
36
<parameter id="-frontend-software-release-url">http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.183:/software/apache-frontend/software.cfg</parameter>
37
will request the third frontend on COMP-1234. All frontends will be of software type "custom-personal". The second frontend will be requested with the state stopped
38 39 40

Note: the way slaves are transformed to a parameter avoid modifying more than 3 lines in the frontend logic.
Important NOTE: The way you ask for slave to a replicate frontend is the same as the one you would use for the software given in "-frontend-quantity". Do not forget to use "replicate" for software type. XXXXX So far it is not possible to do a simple request on a replicate frontend if you do not know the software_guid or other sla-parameter of the master instance. In fact we do not know yet the software type of the "requested" frontends. TO BE IMPLEMENTED
41

42 43 44 45 46 47
XXX Should be moved to specific JSON File
Extra-parameter per frontend with default :
ram-cache-size = 1G
disk-cache-size = 8G


48 49 50 51
How to deploy a frontend server
===============================

This is to deploy an entire frontend server with a public IPv4.
52
If you want to use an already deployed frontend to make your service available
53
via ipv4, switch to the "Example" parts.
54

55 56 57 58 59
First, you will need to request a "master" instance of Apache Frontend with:
  * A "domain" parameter where the frontend will be available
  * A "public-ipv4" parameter to state which public IPv4 will be used

like::
60 61 62
  <?xml version='1.0' encoding='utf-8'?>
  <instance>
   <parameter id="domain">moulefrite.org</parameter>
63
   <parameter id="public-ipv4">xxx.xxx.xxx.xxx</parameter>
64
  </instance>
65 66 67

Then, it is possible to request many slave instances
(currently only from slapconsole, UI doesn't work yet)
68 69 70 71 72 73 74
of Apache Frontend, like::
  instance = request(
    software_release=apache_frontend,
    partition_reference='frontend2',
    shared=True,
    partition_parameter_kw={"url":"https://[1:2:3:4]:1234/someresource"}
  )
75 76 77 78
Those slave instances will be redirected to the "master" instance,
and you will see on the "master" instance the associated RewriteRules of
all slave instances.

79 80
Finally, the slave instance will be accessible from:
https://someidentifier.moulefrite.org.
81

82 83 84 85
About SSL
=========
Default and custom-personal software type can handle specific ssl for one slave instance.
IMPORTANT: One apache can not serve more than One specific SSL VirtualHost and be compatible with obsolete browser (i.e.: IE8). See http://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI
86

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#How to have custom configuration in frontend server
#===================================================
#
#In your instance directory, you, as sysadmin, can directly edit two
#configuration files that won't be overwritten by SlapOS to customize your
#instance:
#
# * $PARTITION_PATH/srv/srv/apache-conf.d/apache_frontend.custom.conf
# * $PARTITION_PATH/srv/srv/apache-conf.d/apache_frontend.virtualhost.custom.conf
#
#The first one is included in the end of the main apache configuration file.
#The second one is included in the virtualhost of the main apache configuration file.
#
#SlapOS will jsut create those two files for you, then completely forget them.
#
#Note: make sure that the UNIX user of the instance has read access to those
#files if you edit them.
104

105 106 107 108 109 110 111 112
Instance Parameters
===================

Master Instance Parameters
--------------------------

domain
~~~~~~
113 114 115 116
name of the domain to be used (example: mydomain.com). Subdomains of this
domain will be used for the slave instances (example:
instance12345.mydomain.com). It is then recommended to add a wildcard in DNS
for the subdomains of the chosen domain like::
117 118 119 120
  *.mydomain.com. IN A 123.123.123.123
Using the IP given by the Master Instance.
"domain" is a mandatory Parameter.

121 122 123 124
public-ipv4
~~~~~~~~~~~
Public ipv4 of the frontend (the one Apache will be indirectly listening to)

125 126
port
~~~~
127
Port used by Apache. Optional parameter, defaults to 4443.
128

129
plain_http_port
130
~~~~~~~~~~~~~~~
131 132
Port used by apache to serve plain http (only used to redirect to https).
Optional parameter, defaults to 8080.
133

134 135 136 137 138
ip-read-limit
~~~~~~~~~~~~~
Use to set IPReadLimit Parameter for antiloris.
Optional parameter, defaults to 10.

139 140 141 142 143 144 145 146 147 148 149
apache_custom_http (custom-group)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jinja template for apache virtualhost http configuration. It will be used by all slaves

apache_custom_https (custom-group)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jinja template for apache virtualhost https configuration. It will be used by all slaves


Slave Instance Parameters (default)
-----------------------------------
150 151 152 153 154

url
~~~
url of backend to use.
"url" is a mandatory parameter.
155
Example: http://mybackend.com/myresource
156

157
enable_cache
158
~~~~~
159
Specify if slave instance should use a squid to connect to backend.
160 161 162
Possible values: "true", "false".
"enable_cache" is an optional parameter. Defaults to "false".
Example: true
163

164
type
165
~~~~
166 167 168
Specify if slave instance will redirect to a zope backend. If specified, Apache
RewriteRule will use Zope's Virtual Host Daemon.
Possible values: "zope", "default".
169
"type" is an optional parameter. Defaults to "default".
170
Example: zope
171

172 173
domain (former custom_domain)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174
Domain name to use as frontend. The frontend will be accessible from this domain.
175
"domain" is an optional parameter. Defaults to
176
[instancereference].[masterdomain].
177 178
Example: www.mycustomdomain.com

179 180 181 182
https-only
~~~~~~~~~~
Specify if website should be accessed using https only. If so, the frontend
will redirect the user to https if accessed from http.
183 184 185
Possible values: "true", "false".
"https-only" is an optional parameter. Defaults to "false".
Example: true
186

187 188 189 190 191 192 193 194 195 196
path
~~~~
Only used if type is "zope".

Will append the specified path to the "VirtualHostRoot" of the zope's
VirtualHostMonster.

"path" is an optional parameter, ignored if not specified.
Example of value: "/erp5/web_site_module/hosting/"

197 198 199 200 201 202
Slave Instance Parameters (custom-personal)
-------------------------------------------

apache_custom_https
~~~~~~~~~~~~~~~~~~~
Raw apache configuration in python template format (i.e. write "%%" for one "%") for the slave listening to the https port. Its content will be templatified in order to access functionalities such as cache access, ssl certificates... The list is available above.
203
NOTE: If you want to use the cache, use the apache option "ProxyPreserveHost On"
204 205 206 207

apache_custom_http
~~~~~~~~~~~~~~~~~~
Raw apache configuration in python template format (i.e. write "%%" for one "%") for the slave listening to the http port. Its content will be templatified in order to access functionalities such as cache access, ssl certificates... The list is available above
208
NOTE: If you want to use the cache, use the apache option "ProxyPreserveHost On"
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

url
~~~
Necesarry to activate cache. url of backend to use.
"url" is an optional parameter.
Example: http://mybackend.com/myresource

domain
~~~~~~
Necesarry to activate cache. The frontend will be accessible from this domain.
"domain" is an optional parameter.
Example: www.mycustomdomain.com

enable_cache
~~~~~~~~~~~~
Necesarry to activate cache.
"enable_cache" is an optional parameter.

ssl_key, ssl_crt, ssl_ca_crt, ssl_crs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SSL certificates of the slave.
They are optional.

Functionalities for apache configuration:
In the slave apache configuration you can use parameters that will be replaced during instanciation. They should be entered as python templates parameters ex:" %(parameter)s"
  * cache_access : url of the cache. Should replace backend url in configuration to use the cache
  * error_log : path of the slave error log in order to log in a deferenciated file.
  * error_log : path of the slave access log in order to log in a deferenciated file.
  * ssl_key, ssl_crt, ssl_ca_crt, ssl_crs : path of the certificates given in slave instance parameters

Slave Instance Parameters (custom-group)
----------------------------------------

url
~~~
Necesarry to activate cache. url of backend to use.
"url" is an optional parameter.
Example: http://mybackend.com/myresource

domain
~~~~~~
Domain name to use as frontend. The frontend will be accessible from this domain.
"domain" is an optional parameter necessary to activate cache. Defaults to
[instancereference].[masterdomain].
Example: www.mycustomdomain.com

The rest of the parameters are defined by templates given to the master and accessible by the slave_parameter dict in it.


258 259 260 261 262
Examples
========

Here are some example of how to make your SlapOS service available through
an already deployed frontend.
263

264 265
Simple Example (default)
------------------------
266

267 268
Request slave frontend instance so that https://[1:2:3:4:5:6:7:8]:1234 will be
redirected and accessible from the proxy::
269 270
  instance = request(
    software_release=apache_frontend,
271
    software_type="RootSoftwareInstance",
272 273 274 275 276 277 278 279
    partition_reference='my frontend',
    shared=True,
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
    }
  )


280 281
Zope Example (default)
----------------------
282

283 284 285
Request slave frontend instance using a Zope backend so that
https://[1:2:3:4:5:6:7:8]:1234 will be redirected and accessible from the
proxy::
286 287
  instance = request(
    software_release=apache_frontend,
288
    software_type="RootSoftwareInstance",
289 290 291 292 293 294 295 296 297
    partition_reference='my frontend',
    shared=True,
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
        "type":"zope",
    }
  )


298 299
Advanced example (default)
--------------------------
300 301

Request slave frontend instance using a Zope backend, with Varnish activated,
302 303 304
listening to a custom domain and redirecting to /erp5/ so that
https://[1:2:3:4:5:6:7:8]:1234/erp5/ will be redirected and accessible from
the proxy::
305 306
  instance = request(
    software_release=apache_frontend,
307
    software_type="RootSoftwareInstance",
308
    partition_reference='my frontend',
309 310
    shared=True,
    partition_parameter_kw={
311
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
312
        "enable_cache":"true",
313
        "type":"zope",
314
        "path":"/erp5",
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
        "domain":"mycustomdomain.com",
    }
  )

Simple Example (custom-personal)
--------------------------------

Request slave frontend instance so that https://[1:2:3:4:5:6:7:8]:1234 will be
  instance = request(
    software_release=apache_frontend,
    software_type="RootSoftwareInstance",
    partition_reference='my frontend',
    shared=True,
    software_type="custom-personal",
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
331

332 333 334 335 336 337 338 339 340 341 342 343
        "apache_custom_https":'
  ServerName www.example.org
  ServerAlias example.org
  ServerAdmin geronimo@example.org
  SSLEngine on
  SSLProxyEngine on
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On
  RewriteRule ^/(.*) https://[1:2:3:4:5:6:7:8]:1234/$1 [L,P]',
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
        "apache_custom_http":'
  ServerName www.example.org
  ServerAlias www.example.org
  ServerAlias example.org
  ServerAdmin geronimo@example.org
  SSLProxyEngine on
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On
  # Remove "Secure" from cookies, as backend may be https
  Header edit Set-Cookie "(?i)^(.+);secure$" "$1"
  # Not using HTTPS? Ask that guy over there.
  # Dummy redirection to https. Note: will work only if https listens
  # on standard port (443).
  RewriteRule ^/(.*) https://[1:2:3:4:5:6:7:8]:1234/$1 [L,P],
    }
  )

Simple Cache Example (custom-personal)
--------------------------------

Request slave frontend instance so that https://[1:2:3:4:5:6:7:8]:1234 will be
  instance = request(
    software_release=apache_frontend,
    software_type="RootSoftwareInstance",
    partition_reference='my frontend',
    shared=True,
    software_type="custom-personal",
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
	"domain": "www.example.org",
	"enable_cache": "True",
379

380 381 382 383 384 385 386 387 388 389 390 391 392
        "apache_custom_https":'
  ServerName www.example.org
  ServerAlias www.example.org
  ServerAlias example.org
  ServerAdmin geronimo@example.org
  SSLEngine on
  SSLProxyEngine on
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On
  RewriteRule ^/(.*) %(cache_access)s/$1 [L,P]',
393

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
        "apache_custom_http":'
  ServerName www.example.org
  ServerAlias www.example.org
  ServerAlias example.org
  ServerAdmin geronimo@example.org
  SSLProxyEngine on
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On

  # Remove "Secure" from cookies, as backend may be https
  Header edit Set-Cookie "(?i)^(.+);secure$" "$1"

  # Not using HTTPS? Ask that guy over there.
  # Dummy redirection to https. Note: will work only if https listens
  # on standard port (443).
  RewriteRule ^/(.*) %(cache_access)s/$1 [L,P],
    }
  )


Advanced example (custom-personal)
----------------------------------

Request slave frontend instance using custom apache configuration, willing to use cache and ssl certificates.
listening to a custom domain and redirecting to /erp5/ so that
https://[1:2:3:4:5:6:7:8]:1234/erp5/ will be redirected and accessible from
the proxy::
  instance = request(
    software_release=apache_frontend,
    software_type="RootSoftwareInstance",
    partition_reference='my frontend',
    shared=True,
    software_type="custom-personal",
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
        "enable_cache":"true",
        "type":"zope",
        "path":"/erp5",
        "domain":"example.org",
436

437 438 439 440 441 442
  	"apache_custom_https":'
  ServerName www.example.org
  ServerAlias www.example.org
  ServerAdmin example.org
  SSLEngine on
  SSLProxyEngine on
443 444 445
  SSLProtocol all -SSLv2 -SSLv3
  SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:HIGH:!aNULL:!MD5
  SSLHonorCipherOrder on
446 447 448 449 450 451 452
  # Use personal ssl certificates
  SSLCertificateFile %(ssl_crt)s
  SSLCertificateKeyFile %(ssl_key)s
  SSLCACertificateFile %(ssl_ca_crt)s
  SSLCertificateChainFile %(ssl_ca_crt)s
  # Configure personal logs
  ErrorLog "%(error_log)s"
453
  LogLevel info
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
  LogFormat "%%h %%l %%{REMOTE_USER}i %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\" %%D" combined
  CustomLog "%(access_log)s" combined
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On
  # Redirect / to /index.html
  RewriteRule ^/$ /index.html [R=302,L]
  # Use cache
  RewriteRule ^/(.*) %(cache_access)s/VirtualHostBase/https/www.example.org:443/erp5/VirtualHostRoot/$1 [L,P]',

    "apache_custom_http":'
  ServerName www.example.org
  ServerAlias www.example.org
  ServerAlias example.org
  ServerAdmin geronimo@example.org
  SSLProxyEngine on
  # Rewrite part
  ProxyVia On
  ProxyPreserveHost On
  ProxyTimeout 600
  RewriteEngine On
  # Configure personal logs
  ErrorLog "%(error_log)s"
479
  LogLevel info
480 481 482 483 484 485 486 487
  LogFormat "%%h %%l %%{REMOTE_USER}i %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\" %%D" combined
  CustomLog "%(access_log)s" combined
  # Remove "Secure" from cookies, as backend may be https
  Header edit Set-Cookie "(?i)^(.+);secure$" "$1"
  # Not using HTTPS? Ask that guy over there.
  # Dummy redirection to https. Note: will work only if https listens
  # on standard port (443).
  RewriteRule ^/(.*)$ https://%%{SERVER_NAME}%%{REQUEST_URI}',
488

489 490 491 492 493 494 495 496 497 498 499 500
    "ssl_key":"-----BEGIN RSA PRIVATE KEY-----
XXXXXXX..........XXXXXXXXXXXXXXX
-----END RSA PRIVATE KEY-----",
    "ssl_crt":'-----BEGIN CERTIFICATE-----
XXXXXXXXXXX.............XXXXXXXXXXXXXXXXXXX
-----END CERTIFICATE-----',
    "ssl_ca_crt":'-----BEGIN CERTIFICATE-----
XXXXXXXXX...........XXXXXXXXXXXXXXXXX
-----END CERTIFICATE-----',
    "ssl_csr":'-----BEGIN CERTIFICATE REQUEST-----
XXXXXXXXXXXXXXX.............XXXXXXXXXXXXXXXXXX
-----END CERTIFICATE REQUEST-----',
501 502
    }
  )
503 504 505 506 507

Notes
=====

It is not possible with slapos to listen to port <= 1024, because process are
508 509
not run as root.

510 511
Solution 1 (IPv4 only)
----------------------
512 513

It is a good idea then to go on the node where the instance is
514
and set some iptables rules like (if using default ports)::
515 516 517

  iptables -t nat -A PREROUTING -p tcp -d {public_ipv4} --dport 443 -j DNAT --to-destination {listening_ipv4}:4443
  iptables -t nat -A PREROUTING -p tcp -d {public_ipv4} --dport 80 -j DNAT --to-destination {listening_ipv4}:8080
518 519 520

Where {public ip} is the public IP of your server, or at least the LAN IP to where your NAT will forward to.
{listening ip} is the private ipv4 (like 10.0.34.123) that the instance is using and sending as connection parameter.
521

522 523
Solution 2 (IPv6 only)
----------------------
524 525 526 527 528 529

It is also possible to directly allow the service to listen on 80 and 443 ports using the following command:

  setcap 'cap_net_bind_service=+ep' /opt/slapgrid/$APACHE_FRONTEND_SOFTWARE_RELEASE_MD5/parts/apache-2.2/bin/httpd

Then specify in the instance parameters "port" and "plain_http_port" to be 443 and 80, respectively.