Category: Plesk

How to Add a Custom HTTP Header to All Sites on a Plesk Server

Adding custom headers is a useful way to identify, trace, or control web traffic across a hosted environment. This guide walks through the process of adding the HTTP header X-Hosted-By: ExampleHost to all websites running on a Plesk server, across both nginx and Apache layers. Why Add a Custom Header? Custom HTTP headers can: Identify the infrastructure powering your site (e.g., for branding or tracing) Assist in diagnostics or security logging Be used for custom caching or CDN logic Step-by-Step: Add Header in nginx Step 1: Copy the nginx Template First, copy the default Plesk template into a custom directory:

Step 2: Edit the Template Open the copied file:

Locate the block that outputs header directives, such as:

Insert your custom header right after:

Step 3: Rebuild nginx Configurations

Step 4: Restart nginx

Step-by-Step: Add Header in Apache Step 1: Copy the Apache Template

Read More »

“One-liner” To Change Plesk Admin Port

Here’s a Bash one-liner to change the Plesk admin port:

Replace XXXX with the desired port number. Explanation sed -i ‘s/listen 8443 ssl;/listen 8444 ssl;/’ /etc/sw-cp-server/conf.d/plesk.conf Searches for listen 8443 ssl; in the configuration file and replaces it with listen 8444 ssl;. sudo systemctl restart sw-cp-server Restarts the Plesk control panel server to apply the new port configuration.            

Read More »

Plesk / Nginx Open Files Limit

Was trying to increase open files limit for nginx on a Plesk server following instructions here: MariaDB on CentOS 7 – “Error in accept: Too many open files” But the limit was not changing. After digging around I found that Plesk was overriding with a config file here: /usr/lib/systemd/system/nginx.service.d/limit_nofile.conf As described here: https://support.plesk.com/hc/en-us/articles/213938485-nginx-fails-to-start-reload-on-a-Plesk-server-Too-many-open-files the easy way to fix open file limit on Plesk is to use: /usr/local/psa/admin/sbin/websrv_ulimits –set 100000 –no-restart

Read More »

Expires Header In Nginx On Plesk

Trying to add an Expires header in Nginx on a Plesk server like this is problematic. The “location” directive conflicts (overrides) the “location” directive created by Plesk. The work around is to disable “Serve static files directly by nginx” but this is a valuable feature that we usually don’t want to turn off. An alternative is to use a “map” directive. Setup the map in the global nginx config by creating /etc/nginx/conf.d/expires_map.conf with: Next in the “Additional nginx directives” field add: This works well but may not be possible on a shared server where the global nginx configuration can not be changed.

Read More »

Nginx Redirects With Map File

Client provided a CSV file with several thousand redirects for site hosted on Plesk server. For maximum efficiency we implemented the redirects using a map file in Nginx. Start by convert the CSV file to a map include file with one redirect per line, space delimited and terminated with a colon. For example: /source-url-1 https://acme.com/dest-url-1: /source-url-2 https://acme.com/dest-url-2: I placed the file at: /var/www/vhosts/acme.com/redirects/redirect.map Next step is to add to global nginx config by creating a file at: /etc/nginx/conf.d/redirect_maps.conf containing: Finally in Plesk, for the target subscription (acme.com) in “Apache & Nginx Setting” add the following to “Additional Nginx directives:

Read More »

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.