Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add new site/server_name in nginx?

Tags:

nginx

I'm just starting to explore nginx on my ubuntu 10.04. I installed nginx and I'm able to get the "Welcome to Nginx" page on localhost. However I'm not able to add a new server_name.

Even when I make the changes in site-available/default. I also tried reloading/restarting nginx, but nothing works.

like image 861
Neo Avatar asked Feb 03 '11 20:02

Neo


People also ask

How do I add a site to nginx?

To enable a website, you must create a symbolic link inside the /etc/nginx/sites-enabled directory pointing to the actual vhost file in /etc/nginx/sites-available . The nginx. conf file reviews the contents of the sites-enabled directory and determines which virtual host files to include.

What is server_name in nginx config?

Server names are defined using the server_name directive and determine which server block is used for a given request. See also “How nginx processes a request”.


1 Answers

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.

like image 197
tutuDajuju Avatar answered Oct 01 '22 18:10

tutuDajuju