Top Nav

Archive | Nginx

ServerAlias On Nginx

On Apache web servers, each virtual host has a “ServerName” directive and zero or more “ServerAlias” directives. When converting to Nginx there is only one directive – “server_name” which takes the place of both of the Apache directives. The “server_name” directive takes a set of space delimited arguments listing domains that should match the virtual host. So for example if you have this Apache config:

Then for Nginx use:

This is a simple example for full details see this page in the Nginx documentation:

http://nginx.org/en/docs/http/server_names.html

2

Canonical Rewrite Rule For Nginx

Need to redirect from acme.com to www.acme.com with nginx? No problem … just add a virtual host declaration for the non-www that redirects like this:

or if you want to add to an existing vhost:

3