How do I add Custom Configurations to the Web Server?

We have optimised our web server, Nginx, so most customers should not make any settings of their own. Sometimes it may, however, be necessary to make customer-specific additions, such as http redirects. Redirects can of course be made directly in WordPress, e.g. with the Redirection plugin.

You can freely make your own changes to the /data/wordpress/nginx/custom.conf file. This file in our system corresponds to the Apache root directory .htaccess file. Put one of the examples in your site's /data/wordpress/nginx/custom.conf, change your site's address and restart Nginx web server to activate changes: wp-restart-nginx.

Here are some common settings you might want to set in your site's Nginx configuration. For more advanced configurations you should check our developer documentation.

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. mycompany.com) and own domain for a product or campaign (myproduct.com)

# Redirect from a certain domain
if ($host ~ myproduct.com) { return 301 https://mydomain.com/myproduct/;}

In order to apply the changes, Nginx must be restarted with the command:


$ wp-restart-nginx

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

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.