How do I add new site/server_name in nginx?

To build on mark’s answer, Debian/Ubuntu distros default configuration file has an include /etc/nginx/sites-enabled/*; directive with site configuration file stored in /etc/nginx/sites-available/, a default site is usually included in that dir.

For examples beyond the default config, follow nginx beginner’s guide or see wiki.nginx.org for more details.

After creating a new configuration in sites-available, create a symbolic link with this command, assuming that your conf file is named “myapp” and nginx is at /etc/nginx (could also be at /usr/local/etc/nginx):

ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp

By the way, you could always create your conf file directly in sites-enabled but the recommended way above allows you to “enable and disable” sites on the server very quickly without actually moving/deleting your conf files.

P.S: Don’t trust the tutorials: check your configuration!

P.P.S: You can use the command nginx -t to test your sites conf and nginx -s reload to reload the conf.

Leave a Comment