Configuring NGINX for Managed WordPress

Posted on by Libby White | Updated:
Reading Time: 2 minutes

Running a WordPress site can be incredibly simple and used right out of the box, but you may need to customize or add specific files in order to get the most out of your site. Our Managed WordPress customers can include custom NGINX configurations for individual sites because we know that adding simple redirects or adjusting browser cache settings are actions that many of our Managed WordPress users do on a regular basis. Read on to learn how you can use this functionality for your own site.

On the Managed WordPress platform, custom configuration files are read from the NGINX folder within the site’s home directory. Any file ending with .conf will be read into NGINX on reload or restart, so a file called ~/nginx/user.conf.sample is provided as a placeholder.

While you can create and edit these files, it is necessary that you reach out to our Managed WordPress Support team to reload the NGINX configuration. This will allow us to test the file configuration and confirm that there are no errors or warnings. Because your site performance and uptime is important, the Managed WordPress support team will manually review files to check for potentially irregular and harmful configurations.

Although the primary use of this feature is for configuring redirects at the NGINX level. you may also set custom browser cache expiration times for static files. Any configurations beyond those described below are considered beyond scope support.

An example of simple redirects is below.

# Simple redirect to an individual page
location /example-redirect-123 {
add_header X-Redirect-By "Yoast SEO Premium";
return 301 /example-redirect;
}

# Rewrite all urls under an old path to a new path
location /category/old-category {
rewrite ^/category/old-category/(.*)$ /category/new-category/$1 permanent;
}

This is an example of adjusting browser cache settings.

# Reduces js and css cache times to a single day instead of the MWP default of 1 year.
location ~* \.(?:css|js)$ {
expires 24h;
access_log off;
add_header Cache-Control "public";
}

If you are looking to block access to a specific directory, you can complete this request by using the following command.

rewrite ^/wp-content/private_directory/(.*) /last;

Where private_directory is the directory you wish to block access to.

Configuring NGINX

1. Log into the site via SSH.

ssh-credentials

2. Navigate to the NGINX directory located in the home directory.

s150@default:~$ pwd
/home/s150
s150@default:~$ cd nginx
s150@default:~ngingx$ ls
user.conf.sample
s150@default:~/nginx$

3. Create a file ending in .conf.

s150@default:~/nginx$ touch redirects.conf
s150@default:~ngingx$ ls
redirects.conf user.conf.sample
s150@default:~/nginx$

In this example, we are using redirects.conf, but you can name it anything you’d like, just make sure you remember the file name.

4. Modify the file with the configuration changes.

s150@default:~/nginx$ vi redirects.conf
s150@default:~ngingx$ cat redirects.conf
# Limited to directives valid in the server block context
# All files ending in '.conf' in this directory will be loaded
# Please contact support to have them reload the nginx config files
# for changes to go into effect.# Configure redirects
#
location /example-redirect-123 {
add_header X-Redirect-By "Yoast SEO Premium";
return 301 /example-redirect;
}
s150@default:~/nginx$

5. Contact support to request review and reload of the config.

Avatar for Libby White

About the Author: Libby White

Former technical writer for Liquid Web. When Libby is not writing for work, she spends time learning more about digital & technical writing, web development, hanging with her family, and taking photographs with her Nikon. Always learning, always growing, never stopping.

Latest Articles

Guide to Bare Metal Restore, Backup, & Recovery

Read Article

How to Upload Information to VMware through SFTP

Read Article

Accessing Man Pages on Ubuntu 16.04 LTS

Read Article

Premium Business Email Pricing FAQ

Read Article

Microsoft Exchange Server Security Update

Read Article