what directory do I put web pages in (nginx) debian?

Sorry but I cannot seem to find the answer by searching here or google.

11 Replies

The "welcome to nginx" page is served from /usr/share/nginx/www. Any file you put in that directory will be viewable at your bare IP address. However, you are not supposed to put your actual website there.

Just use a location that is easy to remember. People usually put website files in one of the following locations. The third form is useful if you have more than one website. If those directories don't exist, just create it.

/var/www

/srv/www

/home//public_html

Then create a virtual host configuration file (in /etc/nginx/sites-available, and linked to /etc/nginx/sites-enabled) to tell nginx that it should use a certain directory to serve certain domains.

I seem to have a file named default in the /etc/nginx/sites-available directory. Do I need a configuration file for each separate domain name? Is the name of the file the same as the domain name?

edit.. I am a bit confused as the default file currently has:

location / {

root /var/www;

index index.html index.htm;

and var/www does not exist on my linode.

It seems that the file in question accepts different entries for each domain although in this example ,http://wiki.nginx.org/VirtualHostExample , the server element is nested withing http.

This is a good guide for getting an nginx server set up and running (along with PHP, if necessary): http://library.linode.com/lemp-guides/debian-6-squeeze.

The specifics of nginx configuration are discussed in ~~[http://library.linode.com/web-servers/nginx/configuration/basic" target="_blank">](http://library.linode.com/web-servers/n … tion/basic">http://library.linode.com/web-servers/nginx/configuration/basic](, too.

Quick answer: Yup, you'll usually want to have a configuration file for each unique web site. You don't need to, and nothing will break if you don't, but it's a good idea. Each enabled configuration will be included into the http block (see /etc/nginx/nginx.conf), so you'd just need to define the server block in the individual files.

@hoopycat:

This is a good guide for getting an nginx server set up and running (along with PHP, if necessary): http://library.linode.com/lemp-guides/debian-6-squeeze.
The nginx portion of that guide isn't particularly helpful. It tells the reader to compile a now-outdated version of nginx and place configuration files in locations that deviate from Debian's standards. Another newbie on this forum was burned by that very same guide a few weeks ago. One could argue that Debian is doing it wrong, but if you're using a well-known binary-based distribution, you should use default packages as much as possible and place your files where all other tutorials assume they're at. It would be much easier to use Dotdeb instead of following the aforementioned guide, or simply to use the default nginx package that comes with Debian.

Anyway, that's a moot point because the OP has already installed nginx.

@marcl:

Do I need a configuration file for each separate domain name? Is the name of the file the same as the domain name?
It is not necessary to have separate configuration files for each domain, but it is generally considered good practice to do so. There are lots of things like that in Linux. Linux allows you to do things any way you want, but there are generally accepted conventions that most people expect you to follow.

@marcl:

It seems that the file in question accepts different entries for each domain although in this example ,http://wiki.nginx.org/VirtualHostExample , the server element is nested withing http.
The http element is probably in /etc/nginx/nginx.conf, which then includes all files in /etc/nginx/sites-enabled. So each virtual host configuration file only needs to have a server element.

The nonexistent /var/www is a known problem with Debian's default nginx package. It's annoying, but it won't have any negative effect on your website if your website is located somewhere else.

@hybinet:

The nginx portion of that guide isn't particularly helpful. It tells the reader to compile a now-outdated version of nginx and place configuration files in locations that deviate from Debian's standards.

Yeah, skip that part. I left out my usual "If You Have To Use A Compiler, You're Doing It Wrong" disclaimer as nginx was already installed.

thanks for your help people.

I did try the compile method first. I thought the version may be outdated so I changed the version number. The process seemed to work well until it came to creating the startup script which I did not work. Not knowing how to solve the problem I figured I'd redeploy debian and do the automated apt-get method.

The version in that is is even more outdate at something like o.6, however it is possible to add the latest nginx to the source list (/etc/apt/sources.list) and run apt to update.

You probably don't need the latest version of nginx. The one that ships with Debian will work much of the time, and it will receive security updates. For some reason, nginx seems to attract the "compile the latest!!!11!!1" crowd more than, say, Apache.

(Did I mention that compiling stuff is usually a bad idea? It's like buying a cow.)

((As an interesting accident of history, PHP seems to attract the "compile the old, unsupported version!!!11!!1" crowd. This probably points to some sort of time scale problem between software developers and distribution managers. Years are very long.))

Also – I'd sneak this in as an edit, but it'd miss the RSS feeds and it's going to rightfully anger some people -- Debian is a stable operating system. Stable, in this sense, doesn't mean "it won't crash" or "it's more reliable"; rather, it means it doesn't change without very good reason. You will run old stuff. Thing is, you will run the same old stuff for years without having to worry about backwards-incompatible changes.

A contrast would be (non-LTS) Ubuntu, which generally(*) runs the latest and greatest, but you will not be running the same version for more than 18 months.

(*) MySQL is an exception, so far. The paperwork for 5.5 is almost done, though. Hooray for copyrights.

EDIT>>>>>>> sorry. forgot to add server to the config , i.e

server {

listen 80;

server_name www.example.com example.com;

access_log /srv/www/example.com/logs/access.log;

error_log /srv/www/example.com/logs/error.log;

location / {

root /srv/www/example.com/public_html;

index index.html index.htm;

}

……………………………………………………………………………..

Can anyone help.trying to follow these instructions.

http://library.linode.com/lemp-guides/debian-6-squeeze

I have created directory structure srv/www/mysite.org.uk/public_html and logs placed a test index.html page in public html. I have created a page titled mysite.org in sites available and followed these instructions

"ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled

/etc/init.d/nginx restart" i changed example.com of course.

The guides is referring to directories such as include / /opt/nginx-sites.conf;

which do not exist. Probably due to installing using apt get.

/opt/etc/nginx/sites-enabled/ this makes sense since the structure exists within etc but this

/opt/nginx-sites.conf does not make sense as nothing exists under opt and I cannot see any nginx-sites.conf file anywhere.

when i restart nginx

Restarting nginx: nginxnginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored

…………………………………….

Then, depending on the size and nature of your deployment, place your virtual host configurations either directly in the /opt/nginx-sites.conf file or include statements for server-specific configuration files in the nginx-sites.file. For more information regarding nginx configuration options, consider our overview of nginx configuration.

http://library.linode.com/web-servers/n … tion/basic">http://library.linode.com/web-servers/nginx/configuration/basic

mentions

/opt/nginx/conf/nginx.conf.

If you installed nginx using apt-get, you do not need to place anything in /opt. The standard location for nginx config files in Debian is /etc/nginx. Ignore everything that involves /opt in the guide, such as the mysterious /opt/nginx-sites.conf file. They can be safely ignored if you installed using apt-get.

The localhost conflict that you mention is probably because of an extra config file being included somewhere. Start from /etc/nginx/nginx.conf, check every include, find the offending server element and kill it.

A quick update, we have a new location for our guide on configuring Nginx:

How to Install NGINX on Debian 10

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct