LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 12-13-2012, 06:43 PM   #1
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Rep: Reputation: 44
Apache with VirtualHosts how to use


Hello all!

I have been using Apache for about 2 years now & I came to realize that I was not using it properly... Its running on a Slackware 13.1 server.

I discovered that my setup was not right when I tried to install and run newznab which requires (according to http://www.howtogeek.com/120285/how-...senet-indexer/) its own VirtualHost.

While I am running about 12 different sites on the same machine (ZOneminder, Horde 4, A Wiki server, rssLounge, etc.) I am not using any VirtualHosts which I believe I should be using...

As of now, each "site" is located in /var/www/htdocs in its own subdirectory

example:

Code:
/var/www/htdocs/rsslounge
/var/www/htdocs/horde4
/var/www/htdocs/zm
...
To access these sites, I simply enter the server's IP followed by the site's folder. For example:

Code:
http://192.168.0.100/horde4/
which brings the Horde4 login page... So far, everything has worked flawlessly. I am not sure if its the right way to do things with Apache. As for newznab, it requires a VH which I tried to setup by modifying /etc/httpd/extra/httpd-vhosts.conf and adding

Code:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName newznab
    DocumentRoot /var/www/htdocs/newznab/www
</VirtualHost>
and uncommenting
Code:
Include /etc/httpd/extra/httpd-vhosts.conf
from /etc/httpd/httpd.conf

And I did the same for all other sites meaning that my VH config file looks like:

Code:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName newznab
    DocumentRoot /var/www/htdocs/newznab/www
</VirtualHost>
<VirtualHost *:80>
    ServerName zm
    DocumentRoot /var/www/htdocs/zm
</VirtualHost>
<VirtualHost *:80>
    ServerName horde4
    DocumentRoot /var/www/htdocs/horde4
</VirtualHost>
...
After saving the config files, running httpd restart and httpd -S (which says Syntax OK), I try to access the sites (for example rsslounge) and I get a 404 not found error page.

Apache's error log says:

Quote:
[Thu Dec 13 18:55:23 2012] [Error] [Client 192.168.0.105] File does not exist: /var/www/htdocs/newznab/www/rsslounge
Looks like whatever I am typing in the browser, Apache always look in the DocumentRoot of the first VirtualHost in the VH config file, and says that the folder is not there...

Obviously I am doing something very wrong.

Can any Apache Guru help a rookie???
Thanks!!!!

Last edited by lpallard; 12-13-2012 at 06:47 PM.
 
Old 12-13-2012, 07:03 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
How are you accessing the page? With a DNS name? Or IP?

-C
 
Old 12-13-2012, 07:12 PM   #3
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
An IP... From any local machine, I type the server's IP followed by the site's folder. My server doesnt have to be accessible from outside (WAN). Only internal connection. Its not really a server in the technical sense since I am the only one using it...

lets say I want to access zoneminder's page, I will type

http://192.168.0.100/zm

simply as that.

Last edited by lpallard; 12-13-2012 at 07:13 PM.
 
Old 12-13-2012, 10:55 PM   #4
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
OK I think Ive managed to get the Virtual hosts working (with the exception of 2 pieces of software, I will come back on these later on).

For now, I am trying to install newznab, following the instructions of http://www.howtogeek.com/120285/how-...senet-indexer/

its not working...

I have created a VH with:

Quote:
<VirtualHost *:80>
ServerName newznab
DocumentRoot /var/www/htdocs/newznab/www
</VirtualHost>
And have newznab sitting in /var/www/htdocs/newznab

Chmod'ed all folders/files according to the link above, Chown'ed everything to the apache user and when I access

I get:

Quote:
Forbidden

You don't have permission to access /newznab/ on this server.
And the apache error log says:

Quote:
[Thu Dec 13 23:52:15 2012] [error] [client 192.168.0.105] Directory index forbidden by Options directive: /var/www/htdocs/newznab/
But when I try to navigate to newznab/install (as per the instructions of the link above), I get:

Quote:
Not Found

The requested URL /newznab/install was not found on this server.
And the apache error log says:

Quote:
[Thu Dec 13 23:53:27 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/newznab/install
Of course the install folder sits in

/var/www/htdocs/newznab/www/install and NOT /var/www/htdocs/newznab/install

Whats wrong??
 
Old 12-14-2012, 04:20 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6
Posts: 1,423

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
You will need a DNS entry pointing the HOST newzab to 192.168.0.100

You can do this in linux machines with /etc/hosts and adding a line

192.168.0.100 newzab

On windows machines you will need to edit the appropriate hosts file c:\windows\system32\drivers\etc\HOSTS http://en.wikipedia.org/wiki/Hosts_(file) has more details on locations of this file.

Then you would access your server as http://newzab and the install page would be http://newzab/install

With the HTTP protocol what your browswer does is take the name newzab, convert it to an IP address (in this case 192.168.0.100) and then makes the request to that IP but says "by the way, I'm looking for site newzab" and apache will then go through your virtual hosts, match that to the ServerName and then use the appropriate document root. (Note to other posters - this is a simplistic explanation but it's close enough for this purpose!)

You can have multiple names for that IP so that in your hosts file you have:

192.168.0.100 newzab zm horde4

Then you'd do exactly the same, and access these as http://newzab http://zm http://horde4 etc.

Hope this helps.
 
1 members found this post helpful.
Old 12-14-2012, 01:11 PM   #6
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Good ! But do I need to add the

Quote:
192.168.0.100 newzab zm horde4
to the /etc/hosts on the machine I am using to access the server OR on the server's /etc/hosts file????

Im comfortable using the server's IP for local browsing.. I admit its not good for public access but at the end of the day my server sits within my network and has no external access whatsoever.

The end result I am trying to achieve is:

From any machine connected to my network (therefore all having separate IP's), launch a web browser

Type

and then I access the site in question.

I will modify the /etc/hosts file ON the server to add the line you suggested as I believe this is the right way to do, then Ill post back.

Please note that I am not browsing the sites from the server but from other machines on the network.

Last edited by lpallard; 12-14-2012 at 01:16 PM.
 
Old 12-14-2012, 09:31 PM   #7
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Ok.. Ive tried everything. Messing around with the .htaccess files, the vhost config file, the general httpd.conf file, created symlinks, etc.. to no avail.

Overall, I have only 2 applications that are not working: rsslounge & newznab

1. rssLounge:
From a fresh start in /var/www/htdocs/rsslounge, I made sure the file ownership & permissions were all as per the installation instructions.

Then, I created a vhost in the apache's vhost config file with:

Quote:
<VirtualHost *:80>
ServerName rsslounge
DocumentRoot /var/www/htdocs/rsslounge
<Directory /var/www/htdocs/rsslounge>
AllowOverride All
ReWriteEngine On
</Directory>
</VirtualHost>
Then started Apache. No errors so far. When I access the site the same way I access the others that are working fine, I get a page without formatting and with no icons. Very far from what I should normally get. Apache complains it cant find some folders & files. From the logs:
Quote:
[Fri Dec 14 20:53:53 2012] [error] [client 192.168.0.106] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
[Fri Dec 14 20:53:53 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
[Fri Dec 14 20:54:00 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/javascript, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:00 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/stylesheets, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:00 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
[Fri Dec 14 20:54:00 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicons, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:00 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
[Fri Dec 14 20:54:12 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/javascript, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:12 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/stylesheets, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:12 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
[Fri Dec 14 20:54:12 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicons, referer: http://192.168.0.100/rsslounge/
[Fri Dec 14 20:54:12 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/rsslounge/favicon.ico
So I started the insanity of creating symlinks so Apache can find what its looking for, but I ended up in an endless creation of symlinks and I gave up and deleted everything.

2. newznab:
Also from a clean install in /var/www/htdocs/newsnab, I made sure the file ownership & permissions were all as per the installation instructions.

Then, I created a vhost in the apache's vhost config file using the proposed vhost in their install file:

Quote:
<VirtualHost *:80>
<Directory /var/www/htdocs/newznab/www/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName newznab
ServerAlias newznab
DocumentRoot /var/www/htdocs/newznab/www
</VirtualHost>
Restarted Apache, no errors in the config. Trying to access the application with http://server-ip/newznab returns

Quote:
Forbidden

You don't have permission to access /newznab/ on this server.
Trying http://server-ip/newznab/install (as per the install instructions), returns

Quote:
Not Found

The requested URL /newznab/install was not found on this server.
Basically same as my previous posts...

Im a wits ends... I need an Apache expert! I crawled the web for hours nothing has helped so far.. Obviously, I dont understand how Apache works and as a result, I believe the redirects dont work.

Other symptom: when I access rsslounge's install page, I see a red error saying:

Quote:
the Apache Module mod_rewrite is not loaded
But its in my httpd.conf file:
Quote:
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
So any further ideas????

 
Old 12-14-2012, 09:40 PM   #8
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,077

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
well the forbidden means that apache doesn't have permission to read the contents of the folder

the contents at the very minimum should be

chmod 644 (rw-r--r--) for files
and
chmod 755 (rwxr-xr-x) for folders

otherwise only the owner would be able to read the files

secondly i wouldn't use /var/www/htdocs as your document root, i would move everything into your home directory (eg /home/{user}/htdocs). yes you will have to chmod +x your home directory, but it would be at the very least easier to edit files you own instead of having to become root every time you want to change your website

Last edited by frieza; 12-14-2012 at 09:42 PM.
 
Old 12-14-2012, 10:07 PM   #9
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
I already had permissions set to 777 recursively on all files & folders within newznab but nevertheless, I changed permissions as you suggested and restarted apache. Unfortunately, did not helped

Last edited by lpallard; 12-14-2012 at 10:09 PM.
 
Old 12-14-2012, 10:27 PM   #10
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,077

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
hmm, try taking out the trailing slash in the directory line and add quotes
Code:
<VirtualHost *:80>
<Directory "/var/www/htdocs/newznab/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName newznab
ServerAlias newznab
DocumentRoot "/var/www/htdocs/newznab/www"
</VirtualHost>
and also make sure the directory newznab is also set to 755

Last edited by frieza; 12-14-2012 at 10:28 PM.
 
Old 12-15-2012, 09:05 AM   #11
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Added the quotes, removed the trailing slash, re-chmod'ed the newznab folder to 755 restarted apache, did httpd -S to verify the vhost config was OK which was, then tried to access newznab.

Same problem...

After further thoughts, I believe the access denied errors are normal for the root of newznab. In this folder, there are other folders that normally wouldnt have tp be accessed by people browsing the application (nzb files, the database, some text files, etc...

So the real error is the File not found error when I try to access /install

Quote:
[Sat Dec 15 10:05:32 2012] [error] [client 192.168.0.105] File does not exist: /var/www/htdocs/newznab/install

Last edited by lpallard; 12-15-2012 at 09:07 AM.
 
Old 12-15-2012, 09:47 AM   #12
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Screwing around, I may have found something...

in my general httpd.conf, I already had two sections:

Quote:
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<Directory "/srv/httpd/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
So I commented the first section, and I can access newznab root folder (NOT the DOCUMENT ROOT) (aka /var/www/htdocs/newznab) and I get a listing of the folder in my browser. Then if I try to access newznab/install I get a "Not found" browser error and apache says "File does not exist: /var/www/htdocs/newznab/install" in its logs.

However if I click on the www folder in the folder listing from my browser, I get the setup page I have been trying to get for so long... I noticed the address in the address bar is

So somethings wrong with the document root of the vhost.
 
Old 12-15-2012, 01:50 PM   #13
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,077

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
hmm, i think i see what it is
if your document root is
Code:
/var/www/htdocs/newznab/www
then the url should simply be
Code:
http://192.168.0.100/install
adding the
Code:
/newsnab/www
to the url is redundant as that part is handled transparently by the server

Last edited by frieza; 12-15-2012 at 02:09 PM.
 
1 members found this post helpful.
Old 12-15-2012, 03:57 PM   #14
descendant_command
Member
 
Registered: Mar 2012
Posts: 757

Rep: Reputation: 159Reputation: 159
To access named vhosts, you must be addressing the server by the relevant name.
If you use the IP, you are getting the default vhost.

You can also set port-based vhosts if you want to use IPort to get to your server, but the simplest way (as described above) is to add the hostnames to your DNS and address it by that.
 
Old 12-16-2012, 11:52 AM   #15
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
I don't understand why you are using Named Virtual Hosts if you're not using DNS. It simply won't work like how you're thinking it will.

If all you want is to be able to access the site with

http://<ip address>/<site>

Then just put you sites under...

Code:
/var/www/htdocs/
               /site1
               /site2
               /site3
               /site4
The you can access it with...

http://<ip address>/site1
http://<ip address>/site2
http://<ip address>/site3
http://<ip address>/site4

--C
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apache and cgi VirtualHosts gabsik Linux - Server 1 10-23-2008 04:20 AM
Apache Virtualhosts and subdomains arew264 Linux - Networking 1 01-03-2006 08:53 AM
Apache VirtualHosts Problem stratisphere Linux - Newbie 4 11-27-2004 12:20 AM
VirtualHosts & apache 2.0.48 TiCkO Linux - Networking 2 07-13-2004 03:20 PM
Virtualhosts in apache. where am i going wrong. SSBN Linux - Networking 20 07-11-2003 04:02 AM


All times are GMT -5. The time now is 02:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration