LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Setting up Apache 2.2 virtual hosts (https://www.linuxquestions.org/questions/slackware-14/setting-up-apache-2-2-virtual-hosts-918102/)

WetDreams 12-10-2011 07:20 PM

Setting up Apache 2.2 virtual hosts
 
I tried to setup a development environment in my local Apache server to have multiple sites, each with its own name. However when I try to access them (ex. http://site1) from a browser I get:
Quote:

Forbidden

You don't have permission to access / on this server.
This is what I have done so far in order to enable vhosts:

Quote:

I created a folder to keep for my projects and added an html file in each site folder

cd
mkdir webdev
cd webdev
mkdir site1 site2

I uncommented the following line in /etc/httpd/httpd.conf
Code:

Include /etc/httpd/extra/httpd-vhosts.conf
and then edited /etc/httpd/extra/httpd-vhosts.conf
Code:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@site1
    DocumentRoot /home/reborn/webdev/site1/
    ServerName site1
    ServerAlias *.site1
    ErrorLog "/var/log/httpd/site1.log"
    CustomLog "/var/log/httpd/site1.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@site2
    DocumentRoot /home/reborn/webdev/site2/
    ServerName site2
    ErrorLog "/var/log/httpd/site2.log"
    CustomLog "/var/log/httpd/site2.log" common
</VirtualHost>

and /etc/hosts
Code:

127.0.0.1    localhost
127.0.0.1    site1 site2

In /var/log/httpd/site1.log I get
Quote:

[Sun Dec 11 02:48:41 2011] [error] [client 127.0.0.1] client denied by server configuration: /home/reborn/webdev/site1/
127.0.0.1 - - [11/Dec/2011:02:48:41 +0200] "GET / HTTP/1.1" 403 202
I can post httpd.conf too, if you need it.

Google hasn't helped me much.
I am using slackware 13.37 and Apache version 2.2.21

EDIT: I want to add that the server worked correctly before and still does if I comment again the line in httpd.conf that includes extra/httpd-vhosts.conf, then I can can access localhost from a browser but uses /var/www/htdocs as DocumentRoot.

custangro 12-10-2011 08:42 PM

You need a "Directory" directive to allow access to the directory...

Something like this...

Code:

<VirtualHost *:80>
<Directory /home/reborn/webdev/site1>
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>
    ServerAdmin webmaster@site1
    DocumentRoot /home/reborn/webdev/site1/
    ServerName site1
    ServerAlias *.site1
    ErrorLog "/var/log/httpd/site1.log"
    CustomLog "/var/log/httpd/site1.log" common
</VirtualHost>

If you have SELinux turned on you may want to set it to "Permissive Mode"

Code:

setenfore 0
-C

Cedrik 12-11-2011 04:54 AM

Yes or make /home/reborn/webdev directory globally available

Code:

NameVirtualHost *:80

<Directory "/home/reborn/webdev">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:80>
    ServerAdmin webmaster@site1
    DocumentRoot /home/reborn/webdev/site1/
    ServerName site1
    ServerAlias *.site1
    ErrorLog "/var/log/httpd/site1.log"
    CustomLog "/var/log/httpd/site1.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@site2
    DocumentRoot /home/reborn/webdev/site2/
    ServerName site2
    ErrorLog "/var/log/httpd/site2.log"
    CustomLog "/var/log/httpd/site2.log" common
</VirtualHost>


WetDreams 12-11-2011 05:40 AM

Yes you are right, I added the "Directory" directive and now everything works!

Thanks a lot!


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