Zeynel
Zeynel

Reputation: 13515

In what directory do I create virtual server directory in nginx?

I am trying to follow this tutorial to use my domain name with my home server. At this point, I enter my IP address and I can see the webpage but I want to be able to use my domain name.

I have a simple question more about Linux than nginx, I guess: In the tutorial he creates a new directory /var/www to keep the site files. Where is this file located? Do I create it in /etc/nginx directory?


Edit

I see that there is var directory in / but I don't see a www file in it. So should I create www in that /var?

Upvotes: 0

Views: 1097

Answers (2)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42849

There's no real correct answer to this, some people use /var/www and some linux distros use /srv for me I prefer putting it inside /home/[user]/www. as long as you write the correct configuration.

check the configuration inside /etc/nginx/nginx.conf at the end of the file it would include a folder which is supposed to be the configuration folder for the virtual hosts, depending on your distro it would either be /etc/nginx/conf.d only or with /etc/nginx/sites-enabled. create a new file and set the root according to what folder you choose.

You'll find that nginx by default uses /usr/share/nginx/html


EDIT: Adding more info according to your comment questions

1- what is root: well inside the nginx config there's a directive called root which tells nginx what folder to look into when a user visits a URL like http://example.com/home.html

Here's the wiki page and here's a sample virtual server for the example I mentioned.

server {
  server_name example.com www.exmaple.com;
  root /usr/share/nginx/html/example; # this is the root i meant
  location / {
    try_files $uri =404;
  }
}

This example will look for home.html inside /usr/share/nginx/html/example/

2- Is it good to use /usr/share/nginx/html: well it's ok doesn't really matter like I said, but since you're going to create a new virtual server anyways might as well dedicate a folder for www. the only qustion here whether it is good practice to use linux's /usr it self, check the directory structure table, you'll find in the table that a linux structure /var it self is more logical

Upvotes: 2

Tharanga Abeyseela
Tharanga Abeyseela

Reputation: 3483

thsi is a good example.

https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

if it's not there, you can create it. (/var/www/) , make sure you give correct permissions.

Upvotes: 1

Related Questions