berth

Websites

Web server settings

How the nginx and Apache stack works, and how to set redirects, HSTS, security headers, protected folders, hotlink protection, error pages, custom directives, per-visitor limits, geoblocking and the write lock.

Updated 9 min readnginx · apache · htaccess · redirect · hsts · headers · geoblockingView as Markdown

On this page
  1. The stack: nginx in front, Apache behind
  2. HTTPS redirect and HSTS
  3. Security headers
  4. Redirects
  5. Protected folders
  6. Hotlink protection
  7. Error pages
  8. .htaccess
  9. Custom nginx and Apache rules
  10. Per-visitor limits
  11. Geoblocking
  12. Write lock
  13. Rules for every site
  14. Related

This article covers the per-domain web server settings in Berth: redirects and HTTPS, security headers, protected folders, hotlink protection and error pages, custom nginx and Apache rules, rate limits per visitor, geoblocking and the write lock. It also explains the server policy and template fragments that let an administrator set rules for every site at once.

Most settings are on the domain page under Settings, Security and Developers. Customers can change them for their own domains unless noted otherwise.

The stack: nginx in front, Apache behind

Berth uses the same arrangement as Plesk:

  • nginx accepts all HTTP and HTTPS traffic, terminates TLS, serves static files, runs the page cache and applies redirects, headers, per-visitor limits and geoblocking.
  • Apache sits behind nginx and handles what needs PHP or .htaccess. It passes PHP to the subscription's own PHP-FPM through mod_proxy_fcgi.

For HTTPS requests nginx talks to Apache over TLS on the loopback interface. A site therefore sees exactly what it saw on Plesk: HTTPS=on, port 443 and the https scheme, in PHP and in mod_rewrite. Common .htaccess rules that send HTTP to HTTPS (RewriteCond %{HTTPS} off, WordPress, Really Simple SSL) do not cause a redirect loop.

Every vhost is rendered from the database, tested with nginx -t and apachectl configtest before it is activated, and rolled back if the test fails. If one domain's configuration becomes invalid later, only that file is set aside and everyone else's changes still go through. See How changes go live.

HTTPS redirect and HSTS

Under Settings → HTTPS:

  • Redirect HTTP to HTTPS sends every plain HTTP request to HTTPS.
  • HSTS tells browsers to use only HTTPS for the domain from then on. Enable it once everything works over HTTPS. You choose the duration (half a year, one year by default, or two years) and whether it covers subdomains (includeSubDomains). internet.nl and the NCSC ask for at least a year.

HSTS and the redirect can also be set when requesting a certificate (berth tls issue --hsts, --no-redirect) or for many domains at once:

berth domain bulk --action redirect_on --domains example.com,example.nl
berth domain bulk --action hsts_on --all

Security headers

Settings → Security headers adds response headers, one per line as Name: value. Allowed are Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy, Cross-Origin-Resource-Policy, X-Robots-Tag and Cache-Control.

X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Content-Security-Policy: default-src 'self'; img-src 'self' data:

The internet.nl check can add the recommended set with one click. An administrator can also require headers on every site through the server policy.

Redirects

The Redirects page of a domain offers two kinds:

  • Forward the whole domain to another address, for example after a rebrand. Choose the status code (301, 302, 307 or 308) and whether to keep the path and query.
  • Redirect individual paths, such as /old to /new, or everything under /old/* to a new location.
berth domain forward --domain example.nl --url https://example.com --code 301 --keep-path
berth domain forward --domain example.nl --off
berth domain redirect add --domain example.com --from /old/* --to /new/ --keep-path
berth domain redirect list --domain example.com

Protected folders

Protected folders puts HTTP Basic authentication on a folder or on the whole site, with users you create there. Passwords are stored as bcrypt hashes.

berth domain protect add --domain example.com --path private --title "Staff only"
berth domain protect list --domain example.com
berth domain protect user-add --domain example.com --id 1 --user anna   # password generated

An empty path protects the whole website, which is useful for a site under construction.

Security → Hotlink protection stops other websites from embedding your images and video and using your bandwidth. They get an error instead of your file. Opening a file directly keeps working, as do browsers that send no referrer. Your own domain and aliases are always allowed; add other sites that may embed, for example google.com for Google Images.

berth domain hotlink --domain example.com --on --ext jpg,png,webp,mp4 --allow google.com

Error pages

With custom error pages on, the panel places example files for 403, 404, 500 and other codes in httpdocs/error_docs/. Edit them to match the site.

berth domain errorpages --domain example.com --on

.htaccess

.htaccess files work as on any Apache host: rewrites and redirects, ErrorDocument, headers and environment variables, handlers and MIME types, caching, authentication and a limited Options. .htaccess cannot enable CGI or server-side includes, and cannot change how PHP is passed to PHP-FPM. That covers what CMSs, plug-ins and frameworks ship with, while keeping the riskiest directives out of reach of a compromised site.

.htaccess may not switch on FollowSymLinks (Apache answers with a 500); use SymLinksIfOwnerMatch instead. Sites migrated or imported into Berth have this rewritten automatically.

Because nginx serves static files directly, .htaccess rules do not apply to images, PDFs and other static files. If you need that (a password on a download folder, an .htaccess hotlink rule), switch on Everything via Apache; see Caching and CDN.

Custom nginx and Apache rules

For things the panel has no setting for, such as an extra location block or a proxy_pass to an app, a domain can carry its own nginx and Apache directives: Developers → Custom web server rules. nginx rules go into the domain's server block, Apache rules into its VirtualHost.

berth domain directives --domain example.com --nginx nginx-extra.conf
berth domain directives --domain example.com --apache - < apache-extra.conf
berth domain directives --domain example.com --clear

Rules are tested before they go live; on an error the previous configuration stays. Every change to a domain reloads the web servers, so changes by customers and resellers that rewrite the web server configuration are paced per account: someone who changes settings in a rapid loop gets a busy, try again shortly answer (429) for a moment. Because custom rules are free-form configuration, they are guarded:

  • Off by default per package. The administrator can always set them. Customers and resellers can only when their package has Allow custom web server rules (berth plan set … --custom-web-directives) or their subscription has that override. A reseller can only enable it in his own packages when the administrator gives him that right.
  • Bound to the subscription. The agent refuses directives that the root processes would execute (loading modules, piped logs, log files outside the domain's log folder), and binds alias, root, proxy_pass and similar to the subscription's own webspace, sockets and ports.
  • Switching it off breaks nothing. Existing rules keep working; the customer can no longer see or change them, only the administrator can.

Per-visitor limits

Security → Per-visitor limits slows down bots and login attacks. Visitors who ask too much get a short 429 Too Many Requests. Limits count per IP address (behind a CDN, the real visitor's address); IPv6 addresses count per /64, so one host cannot dodge the limit by rotating addresses.

LimitOptions
Limit login attemptsOn by default: a fixed limit per address on WordPress wp-login.php and xmlrpc.php, and on Joomla and Drupal logins
Requests per second per addressNo limit, 10, 30 or 100 for the whole site, with bursts of twice that
Concurrent connections per address0 (no limit) or 10–1000
Own pathsA path, a limit per minute (10, 60, 300 or 1200), optionally counting only POST
berth domain ratelimit --domain example.com --login --site 30 --path "/api/ 300" --path "/contact 10 post"
berth domain ratelimit --domain example.com --off

Each call sets the full list again, so name every limit you want to keep. How often limits were hit shows up in the package health; see Site quality scores.

Geoblocking

Security → Geoblocking either blocks visitors from chosen countries or admits only chosen countries. Blocked visitors get a 403. Let's Encrypt's validation requests and addresses without a country (private networks) are always allowed. Only the account owner can change it.

berth domain geo --domain example.com --block RU,CN
berth domain geo --domain example.com --allow NL,BE
berth domain geo --domain example.com --off

Country data comes from DB-IP Lite (CC BY 4.0) and is updated by the panel. An administrator can add own ranges and can geoblock the panel itself; status pages stay reachable:

berth geoip status
printf '198.51.100.0/24 NL\n' | berth geoip overrides
berth geoip panel --allow NL,BE,DE

Write lock

A write lock makes a subscription's websites read-only, so an intruder who gets in through a vulnerable plugin cannot leave a backdoor. Switch it on under Security → Write lock. While it is on:

  • no PHP script, SFTP or FTP account or scheduled task can change files in the document roots,
  • only the writable exceptions you list stay writable (by default wp-content/uploads and wp-content/cache),
  • ownership and permissions do not change; the document roots are mounted read-only.

For an update, lift the lock temporarily for 15 minutes, an hour, four hours or a day; it goes back on by itself, or immediately with Lock again now. The panel's own tools (file manager, WordPress management, restore) lift it briefly when they need to write. The lock applies to the whole subscription.

berth lock on --subscription acme --exceptions wp-content/uploads,wp-content/cache
berth lock unlock --subscription acme --for 1h
berth lock relock --subscription acme
berth lock status --subscription acme

Rules for every site

Two root-only mechanisms let a hosting company set web server rules for all sites, which neither packages nor a compromised panel can loosen.

Server policy

The server policy holds hard limits in TOML files under /etc/berth/beleid.d/. The agent applies them to every PHP pool and vhost; the panel can only read them (Admin → Server policy). Keys include:

KeyEffect
web.custom_directivestoegestaan (allowed), alleen_beheerder (administrator only) or nooit (never)
web.headers_requiredHeaders set on every site; a domain cannot override them
php.mailtoegestaan (allowed) or nooit (never): mail() off everywhere
php.disable_functions_extraExtra functions disabled in every pool
php.max.memory_limit, php.max.upload_max_filesize, php.max.post_max_size, php.max.max_execution_timeUpper bounds for php.ini values
php.versions_allowedThe only PHP versions offered
sudo berth beleid show
sudo berth beleid set web.headers_required 'X-Frame-Options: SAMEORIGIN' 'Referrer-Policy: strict-origin'
sudo berth beleid set php.max.memory_limit 512M
sudo berth beleid check

An unknown key or invalid value makes the whole policy invalid: the last valid version keeps applying, and berth doctor and the policy page show the error. Imports from Plesk, cPanel or another Berth server pass through the same policy.

Template fragments

For configuration the panel does not know, root can place a fragment on a fixed hook in the templates, for all domains or only those of one package: in the nginx server block, in location /, before the proxy to Apache, in the Apache VirtualHost, or at the end of the PHP-FPM pool. The agent fills in variables such as {domein}, {webroot}, {sysuser}, {php_socket} and {logs}, refuses pool fragments that would touch the subscription's sandbox, and the normal config test decides whether it goes live.

The fragments are root-owned files in /etc/berth/local/sjablonen/<template>/<hook>.conf, or <hook>.<package>.conf for one package only. Typical uses: a header or location for every site, a longer timeout for one package, an extra PHP-FPM setting. berth sjablonen check <file> validates a file before you put it in place, berth sjablonen check checks the whole folder, and berth sjablonen list shows which fragments apply to which package and whether the last config test passed with them.

sudo berth sjablonen check
sudo berth domain reprovision --domain example.com   # try one domain first
sudo berth domain reprovision --all