-
Notifications
You must be signed in to change notification settings - Fork 298
Reverse Proxy
This guide outlines how to set up a reverse proxy for Plausible CE using Caddy, Nginx, or Apache. It assumes you arrived here from the quickstart guide.
Note: Starting from version 2.1.2, a reverse proxy is no longer necessary since Plausible CE can handle HTTPS and automatic Let's Encrypt certificates as outlined in the quickstart. The Nginx and Apache configurations provided here have been contributed by the community and have not been tested by the maintainers.
To allow the reverse proxy to communicate with Plausible, set the HTTP port on which you want Plausible to listen:
$ echo "HTTP_PORT=8000" >> .env
$ cat .env
BASE_URL=https://plausible.example.com
SECRET_KEY_BASE=As0fZsJlUpuFYSthRjT5Yflg/NlxkFKPRro72xMLXF8yInZ60s6xGGXYVqml+XN1
HTTP_PORT=8000
And modify compose.override.yml to expose that port to the host:
$ cat > compose.override.yml << EOF
services:
plausible:
ports:
- 127.0.0.1:8000:${HTTP_PORT}
EOF
Then launch and sanity-check it:
$ docker compose up -d
$ curl --head http://localhost:8000
HTTP/1.1 200 OK
...
Caddy automatically manages HTTPS and WebSockets with minimal configuration. Here’s a sample Caddyfile setup:
plausible.example.com {
reverse_proxy localhost:8000
}
Replace plausible.example.com
with your actual domain name, which should match the $BASE_URL
Save this configuration in a file named Caddyfile
, and then run Caddy with:
$ caddy run --config /path/to/Caddyfile
For Nginx, use the following server block configuration:
server {
server_name plausible.example.com;
listen 80;
listen [::]:80;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /live/websocket {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
Replace plausible.example.com
with your actual domain name, matching the $BASE_URL
To enable this configuration:
-
Save the configuration to a file named
plausible
in your Nginx configuration directory. -
Create a symbolic link in the
sites-enabled
directory:$ cp /path/to/plausible /etc/nginx/sites-available/ $ ln -s /etc/nginx/sites-available/plausible /etc/nginx/sites-enabled/plausible
-
Restart Nginx:
$ systemctl restart nginx
For Apache, use the following configuration in your plausible.conf
file:
<VirtualHost *:80>
ServerAdmin admin@plausible.example.com
ServerName plausible.example.com
ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassMatch ^/(live/websocket)$ ws://localhost:8000/$1
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" forwarded
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/access.log forwarded env=forwarded
</VirtualHost>
Replace plausible.example.com
with your actual domain name, which should match the $BASE_URL
Follow these steps to set it up:
-
Enable the necessary Apache modules:
$ a2enmod proxy proxy_http proxy_ajp remoteip headers proxy_wstunnel $ systemctl restart apache2
-
Copy the configuration to Apache’s configuration folder:
$ cp /path/to/plausible.conf /etc/apache2/sites-available/ $ a2ensite plausible.conf $ systemctl restart apache2
Note
Plausible CE is funded by our cloud subscribers. So if you know someone who might find Plausible Cloud useful, please let them know about us!