LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache with VirtualHosts how to use (https://www.linuxquestions.org/questions/linux-server-73/apache-with-virtualhosts-how-to-use-4175441373/)

lpallard 12-13-2012 06:43 PM

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!!!!

custangro 12-13-2012 07:03 PM

How are you accessing the page? With a DNS name? Or IP?

-C

lpallard 12-13-2012 07:12 PM

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.

lpallard 12-13-2012 10:55 PM

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??

TenTenths 12-14-2012 04:20 AM

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.

lpallard 12-14-2012 01:11 PM

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.

lpallard 12-14-2012 09:31 PM

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????

:(

frieza 12-14-2012 09:40 PM

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

lpallard 12-14-2012 10:07 PM

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

frieza 12-14-2012 10:27 PM

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

lpallard 12-15-2012 09:05 AM

:( 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

lpallard 12-15-2012 09:47 AM

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.

frieza 12-15-2012 01:50 PM

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

descendant_command 12-15-2012 03:57 PM

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 IP:port 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.

custangro 12-16-2012 11:52 AM

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

frieza 12-16-2012 03:16 PM

another (possibly overkill) solution is Interface Aliases

each with their own IP address and switching to IP based virtual hosting.For an example, I used it once to host multiple SSL based websites on the same server.

lpallard 12-30-2012 12:06 PM

Quote:

Originally Posted by custangro (Post 4850465)
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

Something in Newznab's configuration or the way the app was written... Outside of a VH it wouldnt work... It was constantly searching for the scripts and php files under /www/ (Apache's root) whereas in real life the files were under /www/newznab/www/ (where they should be). I believe it is because whoever wrote newznab had in mind that it would be the main web application running on the webserver but in my case, its not.

With VH, all is fine now!!!!

Thanks to all who helped here!

moduleWolf 02-21-2013 05:02 PM

@lpallard

Can you post your final diffs from the files you changed? I would like to see your final solution.

lpallard 02-24-2013 08:51 PM

Of course! let me know exactly what you want to see in my config..


For now, apache's extra vhost config file:

Code:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/htdocs/
</VirtualHost>

<VirtualHost *:80>
        ServerName newznabplus
        <Directory /var/www/htdocs/newznabplus/www/>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        DocumentRoot /var/www/htdocs/newznabplus/www
</VirtualHost>

I did not change anything else.... Once this file was modified, all was fine...


All times are GMT -5. The time now is 12:11 AM.