-
Notifications
You must be signed in to change notification settings - Fork 316
Reverse Proxy
This guide outlines how to set up a reverse proxy for Plausible CE using Caddy, Nginx, or Apache. The guide assumes you got here from quickstart.
To make it possible for the reverse proxy to reach Plausible, you would need to modify the compose.override.yml
file to expose Plausible ports to the host:
$ echo "HTTP_PORT=8000" >> .env
$ cat > compose.override.yml << EOF
services:
plausible:
ports:
- 127.0.0.1:8000:${HTTP_PORT}
EOF
$ docker compose up -d
$ curl --head http://localhost:8000
HTTP/1.1 200 OK
access-control-allow-credentials: true
access-control-allow-origin: *
access-control-expose-headers:
cache-control: max-age=0, private, must-revalidate
content-length: 15363
content-type: text/html; charset=utf-8
date: Tue, 24 Sep 2024 07:36:48 GMT
referrer-policy: strict-origin-when-cross-origin
server: Cowboy
x-content-type-options: nosniff
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-request-id: F_gd-E81vrjy83UABkjh
x-robots-tag: noindex, nofollow
Caddy automatically handles HTTPS and WebSockets with minimal configuration. Below is an example Caddyfile setup:
example.com {
reverse_proxy localhost:8000
}
Replace example.com
with your actual domain name. It needs to be the same as in $BASE_URL
. Save this configuration in a file called Caddyfile
, and then run Caddy with:
$ caddy run --config /path/to/Caddyfile
For Nginx, use the following server block configuration:
server {
server_name 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 example.com
with your actual domain name. It needs to be the same as in $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@example.com
ServerName example.com
ProxyPreserveHost On
ProxyAddHeaders On
ProxyPassMatch ^/(live/websocket)$ ws://localhost:8000/$1
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Replace example.com
with your actual domain name. It needs to be the same as in $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!