Configure with Nginx
How to configure remark42 with Nginx reverse proxy
Example of nginx configuration (reverse proxy) running remark42 service on remark42.example.com
server {
listen 443 ssl;
server_name remark42.example.com;
ssl_certificate /etc/nginx/ssl/remark42.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/remark42.example.com.key;
# room for image uploads up to IMAGE_MAX_SIZE (5 MB by default)
client_max_body_size 10m;
gzip on;
gzip_types text/plain application/json text/css application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
gzip_min_length 1000;
gzip_proxied any;
location ~ /\.git {
deny all;
}
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://remark42:8080/;
}
access_log /var/log/nginx/remark42.log;
}
server {
listen 80;
server_name remark42.example.com;
return 301 https://remark42.example.com$request_uri;
}
A single location / is all Remark42 needs: the API, the auth routes and the widget files under /web/ are all served by Remark42 itself.
TLS is enabled with the ssl parameter of listen. The older ssl on; directive was removed in nginx 1.25.1, and a configuration that still uses it fails to load.
client_max_body_size has to exceed IMAGE_MAX_SIZE by enough to cover the multipart encoding around the uploaded file, as nginx answers larger requests with 413 Request Entity Too Large before they reach Remark42. With both set to the same byte count, images close to the limit are rejected; the 10m above covers the default 5 MB. To restore or import a backup through nginx, keep it above the uncompressed size of the largest backup or export as well, since the restore and import commands send a .gz file unpacked.
Note: proxy_pass points to internal DNS name remark42 and is expected to run from the same compose. If Nginx runs outside compose, the real IP (or docker's bridge IP) should be used
Because this config sets X-Real-IP/X-Forwarded-For, set --trusted-proxy to the network Nginx connects from (for a same-compose Nginx that is the Docker network, e.g. 172.16.0.0/12). Without it Remark42 trusts those headers from any client, which lets them spoof their IP and bypass rate limiting and vote de-duplication.