Skip to main content

How do I add Custom Configurations to the Web Server?

Updated today

We have pre-optimized our HTTP server (nginx), so in most cases, you do not need to make custom settings. However, sometimes the need may arise for customer-specific additions, such as HTTP redirects. Redirects are easy to implement directly within WordPress, for instance, with the Redirection plugin or by manually writing wp_rewrite rules. You can also find more information about redirects in our developer documentation.

We only recommend modifying nginx settings if the required changes cannot be achieved using WordPress and its plugins.

Note!

Incorrect settings or redirects can lead to the entire site becoming inaccessible.

If you wish to make changes to the HTTP server settings or redirects, you can create a new file with a .conf extension on the server within the /data/wordpress/nginx/ directory. This file is the equivalent of the Apache root directory's .htaccess file in our system.

Below are some of the most common settings. For example, you can copy one of the examples below into the /data/wordpress/nginx/custom.conf file, replace the example domain with your own site's domain, and restart Nginx by running the command wp-restart-nginx on the command line.

Force All Website Traffic to HTTPS

By default we create a SSL-certificate to all sites in Seravo's hosting. Normally, to enable https, all you need to do is to make sure your Home and Siteurl in WordPress settings start with https://. If for some reason it seems your site still uses the unencrypted http-connection, you can force all traffic to use encrypted https protocol.

# Copy-paste this as-is, do not modify 
if ( $ssl = false ) {
return 301 https://$http_host$request_uri;
}

Redirect a Page to a New Address

Often when you renew your website, the page structure also changes and if people have bookmarks to your pages, they would stop working. In order to keep the old links working, you can redirect old URL's to new ones.

# Simple 302 (temporary) redirect rule 
rewrite ^/original-page https://example.com/new-page/;
# OR
# Simple 301 (permanent) redirect rule
rewrite ^/original-page https://example.com/new-page/ permanent;

Redirect a Domain to a Landing Page

You may have multiple domains pointing to your website, for example your main domain (e.g. example.com) and own domain for a product or campaign (example.org)

# Redirect from a certain domain 
if ($host = example.org) {
return 301 https://example.com/landingpage/;
}

if ($host = www.example.org) {
return 301 https://example.com/landingpage/;
}

For the changes to take effect, nginx must be restarted. You can first test whether the nginx rules are correct using the command:

wp-restart-nginx --test

If everything looks good and the test returns no errors, you can restart nginx with the command:

wp-restart-nginx

Are You Redirecting a New Domain?

In addition to the settings above, you must contact our customer service if the domain is new or has not been previously notified to us. Please notify us of the new domain by sending a message to [email protected].

We will add the supplementary domain to the server's records so that the SSL certificate can be applied and redirects function correctly. After the DNS changes, redirects will start working within approximately one hour.

Learn More

More information on using nginx can be found on the nginx homepage.

Did this answer your question?