Top Nav

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.

0

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:

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:

0

WordPress External Cron

For low traffic WordPress sites, the internal cron will not run on a reliable schedule resulting in missed jobs. For high traffic sites the internal cron can result in excessive cron runs. The solution is to disable the internal cron and setup an external cronjob at the operating system level.

To disable the internal cron add the following to wp-config.php:

For the external cron you can use curl or wget, but my preference is wp-cli like this:

On a Plesk server this might look like:

0

Clearing PHP opcache

Great article on how to clear the PHP opcache:

https://ma.ttias.be/how-to-clear-php-opcache/

To facilitate use on a Plesk server created script and mapped into namespace:

https://acme.com/opcache_clear

Here’s the script:

And here’s the Apache config to map into a virtual host:

This above config should be placed in the “Apache & nginx setting” screen in the “Additional directives for https” field. In addition to setting the alias path we’re also setting the PHP handler.

Additionally under “Password protected directories” added password protection for “/opcache_clear”. This is just a placeholder for the password file which is referenced in the above config.

0

Bash Directory Stack

Ryan at Level1Techs introduces the Bash Directory Stack:

Quick Reference

The Bash Directory Stack is FILO (First In, Last Out)

pushd /some/dir/path

  • push pwd to stack and change to new directory

dirs

  • list stack

dirs -V

  • list stack vertical with index

popd

  • change directory to directory at position 1 in stack

pushd +n

  • change directory to “n” indexed directory
  • actually a rotate
  • also accepts “-n”

popd +n

  • remove indexed item from stack
  • also accepts “-n”

dirs -c

  • clear stack
0