| 1 |
Running LemonLDAP::NG behind a reverse proxy |
| 2 |
============================================ |
| 3 |
|
| 4 |
Your network infrastructure might require that LemonLDAP::NG components |
| 5 |
(Portal, Manager, Handler) run behind a reverse proxy. |
| 6 |
|
| 7 |
|image0| |
| 8 |
|
| 9 |
Transmitting the correct IP address to the portal |
| 10 |
------------------------------------------------- |
| 11 |
|
| 12 |
In this case, LemonLDAP::NG components will store the ip address of the |
| 13 |
connection between the reverse proxy and the webserver in the session, |
| 14 |
and in logs. This prevents features such as session restrictions and |
| 15 |
rules based on \`ipAddr\` from working as expected. |
| 16 |
|
| 17 |
A Content Delivery Network (CDN) would also have the same issue. |
| 18 |
|
| 19 |
In order to make LemonLDAP::NG behave correctly behind a proxy, you need |
| 20 |
to forward the original IP address all the way to LemonLDAP::NG. |
| 21 |
|
| 22 |
In order to do this you have several options. |
| 23 |
|
| 24 |
HTTP Header |
| 25 |
~~~~~~~~~~~ |
| 26 |
|
| 27 |
This generic method is the most likely to work in your particular |
| 28 |
environment. |
| 29 |
|
| 30 |
First, configure your reverse proxy (or CDN) to send the origin IP |
| 31 |
address in a HTTP header. Most reverse proxies do this by default, |
| 32 |
generally in a header named ``X-Forwarded-For`` or ``X-Real-IP``. |
| 33 |
|
| 34 |
Once the header is transmitted to LemonLDAP::NG's web server, you may |
| 35 |
uncomment the relevant parts of the configuration file. |
| 36 |
|
| 37 |
- For Nginx: |
| 38 |
|
| 39 |
.. code-block:: nginx |
| 40 |
|
| 41 |
set_real_ip_from 127.0.0.1; |
| 42 |
real_ip_header X-Forwarded-For; |
| 43 |
|
| 44 |
|
| 45 |
.. tip:: |
| 46 |
|
| 47 |
Make sure Nginx was compiled with the `http_real_ip |
| 48 |
module <http://nginx.org/en/docs/http/ngx_http_realip_module.html>`__\ |
| 49 |
|
| 50 |
- For Apache: |
| 51 |
|
| 52 |
.. code-block:: apache |
| 53 |
|
| 54 |
RemoteIPHeader X-Forwarded-For |
| 55 |
RemoteIPInternalProxy 127.0.0.1 |
| 56 |
|
| 57 |
|
| 58 |
.. tip:: |
| 59 |
|
| 60 |
Make sure the `mod_remoteip |
| 61 |
module <https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html>`__ is |
| 62 |
enabled in your Apache installation |
| 63 |
|
| 64 |
|
| 65 |
.. danger:: |
| 66 |
|
| 67 |
Both modules need you to specify the address of your |
| 68 |
reverse proxy. Using the ``http_real_ip`` or ``mod_remoteip`` module |
| 69 |
might let an attacker impersonate any IP address they want by setting |
| 70 |
the ``X-Forwarded-For`` header themselves. Please read the relevant |
| 71 |
module documentation carefully. |
| 72 |
|
| 73 |
PROXY Protocol |
| 74 |
~~~~~~~~~~~~~~ |
| 75 |
|
| 76 |
Alternatively, if your proxy supports the PROXY protocol (Nginx, |
| 77 |
HAProxy, Amazon ELB), you may use it to carry over the information |
| 78 |
almost transparently. |
| 79 |
|
| 80 |
Refer to your reverse proxy's documentation to find out how to enable |
| 81 |
the PROXY protocol on the reverse proxy side. |
| 82 |
|
| 83 |
Then, on the LemonLDAP::NG side, in the NGINX configuration of your |
| 84 |
Portal/Manager/Handler: |
| 85 |
|
| 86 |
.. code-block:: nginx |
| 87 |
|
| 88 |
listen 80 proxy_protocol; |
| 89 |
# or |
| 90 |
# listen 443 ssl proxy_protocol; |
| 91 |
|
| 92 |
set_real_ip_from 127.0.0.1; |
| 93 |
real_ip_header proxy_protocol; |
| 94 |
|
| 95 |
.. |image0| image:: /documentation/reverseproxy.png |
| 96 |
:class: align-center |
| 97 |
|
| 98 |
|
| 99 |
Fixing handler redirections |
| 100 |
--------------------------- |
| 101 |
|
| 102 |
If your handler server runs behind a reverse proxy, it may have trouble figuring |
| 103 |
out the right URL to redirect you to after logging in. |
| 104 |
|
| 105 |
In this case, you can force a particular port and scheme in the Virtual Host's |
| 106 |
Options. |
| 107 |
|
| 108 |
But is instead you want this scheme to be auto-detected by LemonLDAP (in order to have a |
| 109 |
same VHost domain available over multiple schemes), you can also use the following |
| 110 |
declarations in the handler's virtual host to force LemonLDAP to use the correct port |
| 111 |
and scheme |
| 112 |
|
| 113 |
Nginx |
| 114 |
~~~~~ |
| 115 |
|
| 116 |
:: |
| 117 |
|
| 118 |
fastcgi_param SERVER_PORT 443 |
| 119 |
fastcgi_param HTTPS On |
| 120 |
|
| 121 |
Apache |
| 122 |
~~~~~~ |
| 123 |
|
| 124 |
.. versionadded: 2.0.10 |
| 125 |
|
| 126 |
:: |
| 127 |
|
| 128 |
PerlSetEnv SERVER_PORT 443 |
| 129 |
PerlSetEnv HTTPS On |