README.apache_frontend.txt 6.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
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.


12 13 14 15
How to deploy a frontend server
===============================

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

19 20 21 22 23
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::
24 25 26
  <?xml version='1.0' encoding='utf-8'?>
  <instance>
   <parameter id="domain">moulefrite.org</parameter>
27
   <parameter id="public-ipv4">xxx.xxx.xxx.xxx</parameter>
28
  </instance>
29 30 31

Then, it is possible to request many slave instances
(currently only from slapconsole, UI doesn't work yet)
32 33 34 35 36 37 38
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"}
  )
39 40 41 42
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.

43 44
Finally, the slave instance will be accessible from:
https://someidentifier.moulefrite.org.
45

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

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.

65 66 67 68 69 70 71 72
Instance Parameters
===================

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

domain
~~~~~~
73 74 75 76
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::
77 78 79 80 81 82
  *.mydomain.com. IN A 123.123.123.123
Using the IP given by the Master Instance.
"domain" is a mandatory Parameter.

port
~~~~
83
Port used by Apache. Optional parameter, defaults to 4443.
84

85
plain_http_port
86
~~~~~~~~~~~~~~~
87 88
Port used by apache to serve plain http (only used to redirect to https).
Optional parameter, defaults to 8080.
89 90 91 92 93 94 95 96

Slave Instance Parameters
-------------------------

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

99
enable_cache
100 101
~~~~~
Specify if slave instance should use a varnish / stunnel to connect to backend.
102
Possible values: "true", "false".
103
"enable_cache" is an optional parameter. Defaults to "false".
104
Example: true
105

106
type
107
~~~~
108 109 110
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".
111
"type" is an optional parameter. Defaults to "default".
112
Example: zope
113 114 115 116

custom_domain
~~~~~~~~~~~~~
Domain name to use as frontend. The frontend will be accessible from this domain.
117
"custom_domain" is an optional parameter. Defaults to
118
[instancereference].[masterdomain].
119 120
Example: www.mycustomdomain.com

121 122 123 124 125 126 127
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.
Possible values: "true", "false".
This is an optional parameter. Defaults to false.

128 129 130 131 132 133 134 135 136 137
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/"

138 139 140 141 142
Examples
========

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

144
Simple Example
145
--------------
146

147 148
Request slave frontend instance so that https://[1:2:3:4:5:6:7:8]:1234 will be
redirected and accessible from the proxy::
149 150
  instance = request(
    software_release=apache_frontend,
151
    software_type="RootSoftwareInstance",
152 153 154 155 156 157 158 159 160
    partition_reference='my frontend',
    shared=True,
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
    }
  )


Zope Example
161
------------
162

163 164 165
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::
166 167
  instance = request(
    software_release=apache_frontend,
168
    software_type="RootSoftwareInstance",
169 170 171 172 173 174 175 176 177
    partition_reference='my frontend',
    shared=True,
    partition_parameter_kw={
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
        "type":"zope",
    }
  )


178
Advanced example
179
----------------
180 181

Request slave frontend instance using a Zope backend, with Varnish activated,
182 183 184
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::
185 186
  instance = request(
    software_release=apache_frontend,
187
    software_type="RootSoftwareInstance",
188
    partition_reference='my frontend',
189 190
    shared=True,
    partition_parameter_kw={
191
        "url":"https://[1:2:3:4:5:6:7:8]:1234",
192
        "enable_cache":"true",
193
        "type":"zope",
194
        "path":"/erp5",
195 196 197
        "custom_domain":"mycustomdomain.com",
    }
  )
198 199 200 201 202

Notes
=====

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

205 206
Solution 1 (IPv4 only)
----------------------
207 208

It is a good idea then to go on the node where the instance is
209
and set some iptables rules like (if using default ports)::
210 211 212

  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
213 214 215

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.
216

217 218
Solution 2 (IPv6 only)
----------------------
219 220 221 222 223 224

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.