Setting the server name in Nginx

in Nginx configuration Tags: Nginx

Hypernode makes use of Nginx. Nginx has much better performance than Apache, and allows us to serve your webshop to many more visitors than Apache would. Some Magento module licenses, like OneStepCheckout, are tied to a specific server name (accessible in the environment variable SERVER_NAME). This article explains how to set the server name in Nginx.

Set the same server_name for each storefront

To explicitly set the server name to be mydomain.com, create a file called server.server_name in /data/web/nginx containing:

set $custom_server_name mydomain.com;

This sets the server_name to mydomain.com for all used storefronts.

Dynamically setting the server_name depending on your used storefront

If you use several licenses for multiple storefronts, you can easily set the server_name dynamically using a mapping.
To do this, first make sure no server_name is set already in any configuration. Then create a file called http.servername in /data/web/nginx with the following content:

map $host $custom_server_name {
 hostnames;
   .example.nl example.nl;
   .othersite.nl mydomain.com;
   .example.net example.net;
   .example.com example.com;
}

This way for each domain used in Magento, the server_name is set to the given name in the mapping.

Using the “.” at the beginning of the hostname string, makes sure both example.nl and *.example.com will be used in the mapping.

External resources

6