what directory do I put web pages in (nginx) debian?
11 Replies
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/
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.
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
http://library.linode.com/lemp-guides/debian-6-squeeze
The specifics of nginx configuration are discussed in
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.
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.
(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.))
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.
server {
listen 80;
server_name
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.
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.
mentions
/opt/nginx/conf/nginx.conf.
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: