You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: installation/reverse-proxy-apache.md
+11-9Lines changed: 11 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,13 @@ layout: documentation
3
3
title: Apache Reverse Proxy
4
4
---
5
5
6
+
# Apache Reverse Proxy
7
+
6
8
These are the steps required to use [**Apache 2.4**](https://www.apache.org/), a HTTP server, although you can use [**NGINX**](reverse-proxy-nginx) server or any other HTTP server which supports reverse proxying. If you are familiar with Apache/basic reverse proxy config and are only interested in OpenHAB specific caveats/directives skip to [OpenHAB settings](#openhab-specific-settings)
7
9
8
10
[[toc]]
9
11
10
-
# Installation
12
+
##Installation
11
13
12
14
Apache runs as a service in most Linux distributions, installation should be as simple as:
13
15
@@ -28,7 +30,7 @@ for Fedora/CentOS/Red Hat Enterprise
28
30
29
31
Once installed, you can test to see if the service is running correctly by going to `http://mydomain_or_myip`, you should see the apache2 default page.
30
32
31
-
# Basic Configuration
33
+
##Basic Configuration
32
34
33
35
::: warning Security Warning
34
36
It is not recommended to expose solely the configuration below to the internet.
@@ -56,11 +58,11 @@ If this doesn't fit for you, you just have to replace `localhost` with your open
56
58
57
59
The command `apachectl configtest` can be used to verify any config you write. To enable your new website `a2ensite <config file name>`. Once enabled, you will not have to enable your website again. Configuration can be reloaded with `systemctl reload apache2`. Please make sure to reload and clear browser cookies after every change.
58
60
59
-
# Authentication
61
+
##Authentication
60
62
61
63
Authentication is recommended for additional security. There are many ways to authenticate to a proxy, but basic auth is sufficient **as long as it is over https**. Note the below documentation about [OpenHAB specific auth headers](#authentication-headers).
62
64
63
-
## Adding or Removing users
65
+
###Adding or Removing users
64
66
65
67
To add users to your reverse proxy, you must use following command. Use the `-c` modifier only for your first user. It will create a new password file. **Do not** use the `-c` modifier again as this will remove all previously created users. Don't forget to change _username_ to something meaningful!
66
68
@@ -78,7 +80,7 @@ and to delete an existing user:
78
80
sudo htpasswd -D /etc/apache2/.htpasswd username
79
81
```
80
82
81
-
## Basic Auth
83
+
###Basic Auth
82
84
83
85
The below directives set the auth type to basic, set the auth name, point to our credentials file, and require a user to be authenticated before allowing them to access OpenHAB
84
86
@@ -91,7 +93,7 @@ The below directives set the auth type to basic, set the auth name, point to our
91
93
</Location>
92
94
```
93
95
94
-
# Encryption/HTTPS
96
+
##Encryption/HTTPS
95
97
96
98
In the interest of not duplicating documentation, please see the [nginx encryption documentation](reverse-proxy-nginx#enabling-https) for certificate generation options. The certificate directives for Apache are:
For more details, read the [apache mod_ssl docs](https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslcertificatefile)
105
107
106
-
# OpenHAB Specific Settings
108
+
##OpenHAB Specific Settings
107
109
108
110
These settings are required due to the quirks and features of proxies and/or OpenHAB.
109
111
110
-
## Authentication Headers
112
+
###Authentication Headers
111
113
112
114
If you use authentication with your reverse proxy, the following two directives are necessary in OpenHAB 3.0 and later.
113
115
@@ -119,7 +121,7 @@ This ensures that OpenHAB uses an alternative auth header, so it does not confli
119
121
120
122
This ensures that your proxy does not send your proxy authentication credentials to OpenHAB, interfering with login (and potentially sending them in plain text across a network).
121
123
122
-
# Putting it All Together
124
+
##Putting it All Together
123
125
124
126
Below is a minimal configuration for a reverse proxy that listens for https requests only, uses basic auth, and proxies to 8080 (default OpenHAB http port).
Copy file name to clipboardExpand all lines: installation/reverse-proxy-nginx.md
+21-20Lines changed: 21 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,13 @@ layout: documentation
3
3
title: NGINX Reverse Proxy
4
4
---
5
5
6
+
# NGINX Reverse Proxy
6
7
7
8
These are the steps required to use [**NGINX**](https://nginx.org), a lightweight HTTP server, although you can use [**Apache**](reverse-proxy-apache) server or any other HTTP server which supports reverse proxying.
8
9
9
10
[[toc]]
10
11
11
-
# Installation
12
+
##Installation
12
13
13
14
NGINX runs as a service in most Linux distributions, installation should be as simple as:
Once installed, you can test to see if the service is running correctly by going to `http://mydomain_or_myip`, you should see the default "Welcome to nginx" page.
20
21
If you don't, you may need to check your firewall or ports and check if port 80 (and 443 for HTTPS later) is not blocked and that services can use it.
21
22
22
-
# Basic Configuration
23
+
##Basic Configuration
23
24
24
25
NGINX configures the server when it starts up based on configuration files.
25
26
The location of the default setup is `/etc/nginx/sites-enabled/default`. To allow NGINX to proxy openHAB, you need to change this file (make a backup of it in a different folder first).
@@ -72,12 +73,12 @@ sudo service nginx restart
72
73
73
74
...and then go to `http://mydomain_or_myip` to see your openHAB server.
74
75
75
-
# Authentication
76
+
##Authentication
76
77
77
78
For further security, you may wish to ask for a **username and password** before users have access to openHAB.
78
79
This is fairly simple in NGINX once you have the reverse proxy setup, you just need to provide the server with a basic authentication user file.
79
80
80
-
## Adding or Removing users
81
+
###Adding or Removing users
81
82
82
83
You will be using _htpasswd_ to generate a username/password file, this utility can be found in the apache2-utils package:
Once again, any changes you make to these files **must be followed with restarting the NGINX service** otherwise no changes will be made.
105
106
106
-
## Referencing the File in the NGINX Configuration
107
+
###Referencing the File in the NGINX Configuration
107
108
108
109
Now the configuration file (`/etc/nginx/sites-enabled/openhab`) needs to be edited to use this password.
109
110
Open the configuration file and **add** the following lines underneath the proxy_* settings:
@@ -113,7 +114,7 @@ Open the configuration file and **add** the following lines underneath the proxy
113
114
auth_basic_user_file /etc/nginx/.htpasswd;
114
115
```
115
116
116
-
## Add authorization and cookie directives in NGINX Configuration
117
+
###Add authorization and cookie directives in NGINX Configuration
117
118
118
119
This is an important new requirement in openHAB 3.0 and later versions.
119
120
This is not required prior to openHAB 3.0. You must add the following two directives underneath the `add_header` (in the `server` block) and `proxy_set_header` (in the `location /` block) items respectively:
@@ -125,12 +126,12 @@ This is not required prior to openHAB 3.0. You must add the following two direct
125
126
126
127
Once done, **test and restart your NGINX service** and authentication should now be enabled on your server!
127
128
128
-
## Use a client certificate based authentication
129
+
###Use a client certificate based authentication
129
130
130
131
You can find a short tutorial in the community forum on how to do so.
131
132
[Using NGINX Reverse Proxy for client certificate authentication](https://community.openhab.org/t/using-nginx-reverse-proxy-for-client-certificate-authentication-start-discussion/43064)
132
133
133
-
## Making Exceptions for Specific IP addresses
134
+
###Making Exceptions for Specific IP addresses
134
135
135
136
It is often desirable to allow specific IPs (e.g. the local network) to access openHAB without needing to prompt for a password or to block everyone else entirely.
136
137
In these cases NGINX can use the `satisfy any` directive followed by `allow` and `deny` lines to make these exceptions.
@@ -146,7 +147,7 @@ These lines are placed in the `location{}` block. For example, by adding the lin
146
147
NGINX will allow anyone within the 192.168.0.0/24 range **and** the localhost to connect without a password.
147
148
If you have setup a password following the previous section, then the rest will be prompted for a password for access.
148
149
149
-
# Setting up a Domain
150
+
##Setting up a Domain
150
151
151
152
To generate a trusted certificate, you need to own a domain. To acquire your own domain, you can use one of the following methods:
152
153
@@ -156,15 +157,15 @@ To generate a trusted certificate, you need to own a domain. To acquire your own
156
157
| Obtaining a free domain |[FreeNom](https://www.freenom.com)| Setup is the same as above. |
157
158
| Using a "Dynamic DNS" service |[No-IP](https://www.noip.com), [Dyn](https://www.dyn.com/dns), [FreeDNS](https://freedns.afraid.org)| Uses a client to automatically update your IP to a domain of you choice, some Dynamic DNS services (like FreeDNS) offer a free domain too. |
158
159
159
-
# Enabling HTTPS
160
+
##Enabling HTTPS
160
161
161
162
Encrypting the communication between client and the server is important because it protects against eavesdropping and possible forgery.
162
163
The following options are available depending if you have a valid domain:
163
164
164
165
If you have a **valid domain and can change the DNS** to point towards your IP, follow the [instructions for Let's Encrypt](#using-lets-encrypt-to-generate-trusted-certificates).
165
166
If you need to use an internal or external IP to connect to openHAB, follow the [instructions for OpenSSL](#using-openssl-to-generate-self-signed-certificates).
166
167
167
-
## Using OpenSSL to Generate Self-Signed Certificates
168
+
###Using OpenSSL to Generate Self-Signed Certificates
168
169
169
170
OpenSSL is also packaged for most Linux distributions, installing it should be as simple as:
You will be prompted for some information which you will need to fill out for the certificate, when it asks for a **Common Name**, you may enter your IP Address:
188
189
Common Name (e.g. server FQDN or YOUR name) []: xx.xx.xx.xx
189
190
190
-
## Using Let's Encrypt to Generate Trusted Certificates
191
+
###Using Let's Encrypt to Generate Trusted Certificates
191
192
192
193
::: tip
193
194
Skip this step if you have no domain name or have already followed the instructions for OpenSSL
194
195
:::
195
196
196
197
Let's Encrypt is a service that allows anyone with a valid domain to automatically generate a trusted certificate, these certificates are usually accepted by a browser without any warnings.
197
198
198
-
### Setting up the NGINX Proxy Server to Handle the Certificate Generation Procedure
199
+
####Setting up the NGINX Proxy Server to Handle the Certificate Generation Procedure
199
200
200
201
Let's Encrypt needs to validate that the server has control of the domain.
201
202
The simplest way of doing this is using a **webroot plugin** to place a file on the server, and then access it using a specific url: _/.well-known/acme-challenge_.
@@ -215,7 +216,7 @@ Next add the new location parameter to your NGINX config, this should be **place
215
216
}
216
217
```
217
218
218
-
### Using Certbot
219
+
####Using Certbot
219
220
220
221
Certbot is a tool which simplifies the process of obtaining secure certificates.
221
222
The tool may not be packaged for some Linux distributions so installation instructions may vary, check out [their website](https://certbot.eff.org/) and follow the instructions **using the webroot mode**.
@@ -225,7 +226,7 @@ Don't forget to change the example domain to your own! An example of a valid cer
If you followed one of the two guides for OpenSSL or Let's Encrypt above, the certificate and key should have been placed in `/etc/letsencrypt/live/mydomain_or_myip/` or `/etc/ssl/` respectively.
231
232
NGINX needs to be told where these files are and then enable the reverse proxy to direct HTTPS traffic, using Strict Transport Security to prevent man-in-the-middle attacks.
@@ -242,7 +243,7 @@ In the NGINX configuration, place one of the following underneath your server_na
## Setting Your NGINX Server to Listen to the HTTPS Port
246
+
###Setting Your NGINX Server to Listen to the HTTPS Port
246
247
247
248
Regardless of the option you choose, make sure you change the port to listen in on HTTPS traffic.
248
249
@@ -255,7 +256,7 @@ You can check by going to `https://mydomain_or_myip` and confirming with your br
255
256
**Let's Encrypt certificates expire within a few months** so it is important to run the updater in a cron expression (and also restart NGINX) as explained in the Certbot setup instructions.
256
257
If you want to keep hold of a HTTP server for some reason, just add `listen 80;` and remove the Strict-Transport-Security line.
257
258
258
-
## Redirecting HTTP Traffic to HTTPS
259
+
###Redirecting HTTP Traffic to HTTPS
259
260
260
261
You may want to redirect all HTTP traffic to HTTPS, you can do this by adding the following to the NGINX configuration.
261
262
This will essentially replace the HTTP url with the HTTPS version!
@@ -279,7 +280,7 @@ server {
279
280
}
280
281
```
281
282
282
-
# Putting it All Together
283
+
##Putting it All Together
283
284
284
285
After following all the steps on this page, you _should_ have a NGINX server configuration (`/etc/nginx/sites-enabled/openhab`) that looks like this:
285
286
@@ -331,7 +332,7 @@ server {
331
332
}
332
333
```
333
334
334
-
# Additional HTTPS Security
335
+
##Additional HTTPS Security
335
336
336
337
To test your security settings [SSL Labs](https://www.ssllabs.com/ssltest/) provides a tool for testing your domain against ideal settings (Make sure you check "Do not show the results on the boards" if you don't want your domain seen).
337
338
@@ -364,7 +365,7 @@ All of these settings are customizable, but make sure you [read up on](https://n
364
365
Feel free to test the new configuration again on [SSL Labs](https://www.ssllabs.com/ssltest/).
365
366
If you're achieving A or A+ here, then your client-openHAB communication is very secure.
366
367
367
-
## Further Reading
368
+
###Further Reading
368
369
369
370
The setup above is a suggestion for high compatibility with an A+ rating at the time of writing, however flaws in these settings (particularly the cyphers) may become known overtime.
370
371
The following articles may be useful when understanding and changing these settings.
Synology DSM (as of 6.2) has the ability to automatically acquire certificates from Let's Encrypt and renew them every 90 days as required.
8
10
The majority of the configuration can be completed through the DSM GUI, but SSH access is required to implement authentication (**authentication is essential for remote access to your openHAB instance**).
0 commit comments