Skip to content

Web server configuration (Nginx/Apache) ​

Each website has its own web server configuration page, where you can add redirects, password-protect the site, or insert custom configuration without SSH-ing into the server.

Open the website and choose Nginx (or Apache, depending on the web server installed on the server) > Configuration in the website menu. Everything on this page applies to both Nginx and Apache, except where marked Nginx only.

INFO

Websites on a server running OpenLiteSpeed do not have this menu. See OpenLiteSpeed.

To manage the web server at the server level (restart it, view the global configuration files, update it), see Nginx on the server.

Page layout ​

  • Top row of buttons: View Configuration, Access Log, Error Log, Redirect, Restricted Access. On the right are the Sync button and the web server management buttons (config, log, start, restart, stop).
  • Below is the website's full configuration, split into 3 areas by position:
    • before: blocks placed before the main server block.
    • server: blocks inside the main server block (for Apache, the <VirtualHost> block).
    • after: blocks placed after the main server block.
  • Each block shows its name (memo) and content, with Edit and Delete buttons (when allowed). A green block name means synced; red means it has unsynced changes.

Click View Configuration to see the current configuration file on the server.

Sync configuration ​

All changes (adding, editing, deleting blocks) are only saved in FlashPanel until you sync. While there are unsynced changes, the page shows the warning You have unsynchronized configuration changes.

Click Sync (at the top, in the warning, or next to a red block) to write the configuration to the server and reload the web server.

TIP

Before reloading, the configuration syntax is checked. If there is an error, the sync event fails (with Nginx, the previous configuration is kept so the website is not interrupted). Open the Events page to read the error, fix the block, then sync again.

Redirect Rules ​

Redirect rules automatically send visitors from one path to another. With Nginx, rules are built on the rewrite directive, so you can use regular expressions. For example, ^/$ matches only the root of the domain.

TIP

To redirect between www and non-www, or to force HTTPS, use the URL Redirects page instead of writing rules yourself.

Create a redirect rule ​

  1. Click Redirect.
  2. Fill in:
    • Memo: a name to remember the rule by.
    • From / To: the source and destination paths.
    • Type: temporary redirect, permanent redirect, last, or break (last and break are Nginx only).
  3. Click New Rewrite Rule, then click Sync.

Edit a redirect rule ​

  1. Find the rule in the server area and click Edit.
  2. Change the details, click Edit Rewrite Rule, then click Sync.

Choose a redirect type ​

  • Temporary redirect (HTTP 302): the browser goes to the destination but does not remember it. If you change the destination, visitors see the change immediately.
  • Permanent redirect (HTTP 301): the browser remembers it and next time goes straight to the destination. If you change the destination, visitors must clear their browser cache to see the change, so think carefully before using it.
  • last (Nginx only): no redirect is returned to the browser. Nginx stops processing the current rewrite rules and searches for a location matching the new path.
  • break (Nginx only): like last, but the new path is processed within the current location.

Security Rules ​

Security rules password-protect the website with HTTP basic authentication. You can protect the whole website or a single path.

Create a security rule ​

  1. Click Restricted Access.
  2. Fill in:
    • Memo: a name to remember the rule by.
    • Path (optional): the path to protect. Leave it blank to protect the whole website.
    • Username and Password: enter them, then click the + button to add them to the list. You can add several accounts; click the x button to remove one.
  3. Click New Security Rule, then click Sync.

Edit a security rule ​

  1. Find the rule in the server area and click Edit.
  2. Add or remove accounts, change the path, click Edit Security Rule, then click Sync.

Credentials are per rule

Each security rule has its own list of accounts. To use the same account for several paths, add it to each rule. To change a password, remove the old account and add it again with the new password.

Custom configuration blocks ​

You can insert any Nginx/Apache configuration in one of three positions: before, server, after.

Add a configuration block ​

  1. Click Add Custom Config (before), Add Custom Config (server), or Add Custom Config (after) depending on where you want the block.
  2. Fill in:
    • Memo: a name shown only in FlashPanel.
    • Position: Before Block Server, In Block Server, or After Block Server.
    • The configuration content (Nginx or Apache syntax, depending on the web server).
  3. Click Add Custom Config, then click Sync.

Edit or delete a configuration block ​

  1. Find the block in its area and click Edit.
  2. Change the content, click Edit Nginx Configuration (the button has this name for both Nginx and Apache), then click Sync.

To delete a block, click Delete next to it, confirm, then click Sync.

WARNING

  • Blocks created by FlashPanel (such as the website's main configuration block) can only have their content edited; their name and position cannot be changed and they cannot be deleted. Be careful when editing them.
  • A block in the server position cannot be moved to another position. If needed, create a new block in the desired position and delete the old one.
  • If the block is a redirect rule or security rule, Edit opens that rule's own form.

Example: use a different PHP version for a subfolder (Nginx only) ​

Suppose your website has a subfolder subfolder running different code that needs a PHP version other than the one the website uses.

  1. Click Add Custom Config (server).

  2. Enter the following content, then click Add Custom Config and Sync:

    nginx
    location ^~ /subfolder/ {
        try_files $uri $uri/ /subfolder/index.php?$query_string;
        location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php/php8.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

Where:

  • Replace subfolder with the actual subfolder name.
  • Replace 8.1 with the PHP version you want. That version must already be installed on the server (see PHP).
  • If the website runs as a system user other than flashpanel, use the socket that includes the user name, for example php8.1-fpm-username.sock. See PHP-FPM sockets per user.

Error log and access log ​

The website's Nginx (or Apache) menu also has two items:

  • Error Log: the website's error log, useful for troubleshooting (for example a 502 Bad Gateway error).
  • Access Log: the log of requests to the website.

If the configuration declares several log files, pick one in the Log file list at the top of the page. The last lines of the log are shown below with their colors kept: choose how many Lines to show, turn on Auto refresh to reload every 5 seconds, or click the refresh button. Click Live View to follow the log in real time in a terminal. You can also open these logs quickly with the Error Log and Access Log buttons on the configuration page.