Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apache2 reverse proxy documentation #4502

Merged
merged 16 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ web/node_modules
web/coverage
core
!/web/**/*.ts
.idea/*
76 changes: 76 additions & 0 deletions docs/docs/guides/reverse_proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
id: reverse_proxy
title: Setting up a Reverse Proxy
---
This guide outlines the basic configuration steps needed to expose your Frigate UI to the internet.
A common way of accomplishing this is to use a reverse proxy webserver between your router and your Frigate instance.
blacknell marked this conversation as resolved.
Show resolved Hide resolved
A reverse proxy accepts HTTP requests the public internet and redirects them transparently to an internal webserver on your network.
blacknell marked this conversation as resolved.
Show resolved Hide resolved

The suggested steps are:
- **Configure** a 'proxy' HTTP webserver (such as [Apache2](https://httpd.apache.org/docs/current/)) and only expose ports 80/443 from this webserver to the internet
blacknell marked this conversation as resolved.
Show resolved Hide resolved
blacknell marked this conversation as resolved.
Show resolved Hide resolved
- **Encrypt** content from the proxy webserver by installing SSL (such as with [Let's Encrypt](https://letsencrypt.org/)). Note that SSL is then not required on your Frigate webserver as the proxy encrypts all requests for you
- **Restrict** access to your Frigate instance at the proxy using, for example, password authentication

:::caution
A reverse proxy can be used to secure access to an internal webserver but the user will be entirely reliant
on the steps they have taken. You must ensure you are following security best practice.
blacknell marked this conversation as resolved.
Show resolved Hide resolved
This page does not attempt outline the specific steps needed to secure your internal website.
blacknell marked this conversation as resolved.
Show resolved Hide resolved
Please use your own knowledge to assess and vet them before you install anything on your system.
blacknell marked this conversation as resolved.
Show resolved Hide resolved
:::

There are several technologies available to implement reverse proxies. This document currently suggests one, using Apache2,
and the community is invited to document others through a contribution to this page.
## Apache2 Reverse Proxy

blacknell marked this conversation as resolved.
Show resolved Hide resolved
In the configuration examples below, only the directives relevant to the reverse proxy approach above are included.
On Debian Apache2 the configuration file will be named along the lines of `/etc/apache2/sites-available/cctv.conf`
### Step 1: Configure the Apache2 Reverse Proxy
Make life easier for yourself by presenting your Frigate interface as a DNS sub-domain rather than as a sub-folder of your main domain.
Here we access Frigate via https://cctv.mydomain.co.uk
blacknell marked this conversation as resolved.
Show resolved Hide resolved
```xml
<VirtualHost *:443>
ServerName cctv.mydomain.co.uk

ProxyPreserveHost On
ProxyPass "/" "http://frigatepi.local:5000/"
ProxyPassReverse "/" "http://frigatepi.local:5000/"

ProxyPass /ws ws://frigatepi.local:5000/ws
ProxyPassReverse /ws ws://frigatepi.local:5000/ws

ProxyPass /live/ ws://frigatepi.local:5000/live/
ProxyPassReverse /live/ ws://frigatepi.local:5000/live/

RewriteEngine on
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://frigatepi.local:5000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://frigatepi.local:5000/$1 [P,L]
</VirtualHost>
```
### Step 2: Use SSL to encrypt access to your Frigate instance
Whilst this won't, on its own, stop access to your Frigate webserver it will encrypt all content (such as login credentials).
blacknell marked this conversation as resolved.
Show resolved Hide resolved
Installing SSL is beyond the scope of this document but [Let's Encrypt](https://letsencrypt.org/) is a widely used approach.

This Apache2 configuration snippet then results in unencrypted requests being redirected to webserver SSL port
```xml
<VirtualHost *:80>
ServerName cctv.mydomain.co.uk

RewriteEngine on
RewriteCond %{SERVER_NAME} =cctv.mydomain.co.uk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
```
### Step 3: Authenticate users at the proxy
There are many ways to authenticate a website but a simple straightforward approach is to use [Apache2 password files](https://httpd.apache.org/docs/2.4/howto/auth.html).
blacknell marked this conversation as resolved.
Show resolved Hide resolved
```xml
<VirtualHost *:443>
<Location />
AuthType Basic
AuthName "Restricted Files"
AuthUserFile "/var/www/passwords"
Require user paul
</Location>
</VirtualHost>
```
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
"guides/false_positives",
"guides/ha_notifications",
"guides/stationary_objects",
"guides/reverse_proxy",
],
Configuration: [
"configuration/index",
Expand Down