Skip to content

Run ClientFence on Nginx

Nginx does not read the .htaccess file that keeps ClientFence’s code and data private on Apache, LiteSpeed and OpenLiteSpeed. On Nginx, add the rules below to the site’s server block instead. Leave .htaccess in place: the installer checks for it, and Nginx ignores it.

  1. Open the Nginx configuration of the site (for example /etc/nginx/sites-available/billing.example.com).

  2. Put these rules in its server block, above any location ~ \.php$ block your hosting panel added. Change root to the folder that holds index.php, and fastcgi_pass to your PHP-FPM socket.

    server {
    server_name billing.example.com;
    root /var/www/clientfence;
    index index.php;
    client_max_body_size 64m;
    # Private code and data
    location ^~ /library/ { return 403; }
    location ^~ /vendor/ { return 403; }
    location ^~ /locale/ { return 403; }
    location ^~ /data/ { return 403; }
    location ^~ /install/sql/ { return 403; }
    location ~* ^/(modules|themes)/[^/]+/manifest\.json$ { return 403; }
    location ~* ^/themes/(?:[^/]+/)+config/ { return 403; }
    # Sensitive file types and hidden files
    location ~* \.(htaccess|htpasswd|bak|conf|inc|ini|lock|log|old|sh|sql|twig|ya?ml)$ { return 403; }
    location ~* (composer\.json|README\.md|CHANGELOG\.md)$ { return 403; }
    location ~ /\.(?!well-known/) { return 403; }
    # Clients may not change hosting domains or usernames
    location ~* /api/client/servicehosting/change_(domain|username) { return 403; }
    location = /enhance { return 302 /hosting; }
    # WHMCS Licensing Addon checks (software sold with WHMCS)
    location = /modules/servers/licensing/verify.php { rewrite ^ /index.php?_url=/licence/verify last; }
    # WHMCS affiliate links (/aff.php?aff=CODE)
    location = /aff.php { rewrite ^ /index.php?_url=/aff.php last; }
    location / { try_files $uri $uri/ /index.php?$query_string; }
    # Only the entry points and the installer run PHP
    location ~ ^/(index\.php|ipn\.php|install/index\.php|install/install\.php)$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout 300;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    }
    location ~* \.php$ { return 403; }
    }
  3. Test the configuration and reload Nginx.

    Terminal window
    nginx -t && systemctl reload nginx
  4. Run the web installer as usual.

client_max_body_size lets ticket attachments, payment receipts and the WHMCS import through: Nginx refuses uploads over 1 MB without it. Set PHP’s upload_max_filesize and post_max_size to match.

Go to System → Settings → System, open the System Health tab and select Run checks now. Private paths blocked asks your site for files that must stay private and lists any it gets back. If it lists something, a rule is missing, or your panel’s own PHP rule comes before the ones above. Pack .htaccess rules reads the file only, so it says nothing about Nginx.

See System Health for the other checks.

Updates cannot change your Nginx configuration. If a release adds a rule, its release notes say so and this page shows it: add it to your server block, reload Nginx and run System Health again. For the rest of the server, see the server security checklist.