2

I was messing around with virtual hosts and now I'm getting a 403 error when trying to access files on the webroot.

Here's my httpd-vhosts.conf:

NameVirtualHost *:80

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


<VirtualHost *:80>
    ServerName test.ts
    DocumentRoot /var/www/htdocs/vhost_test 
    <Directory /var/www/htdocs/vhost_test>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I'm pretty sure its a problem with vhosts because I commented out the line that included httpd-vhosts.conf on httpd.conf and the problem was gone. What's wrong with it?

EDIT: a day after Phil Hollenback helped me with this problem, the server began acting up again. Same problem as before, and doing what I did before didn't solve it this time. So I tried changing httpd-vhosts.conf with this:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www
    <Directory />                   #added this tag
        Allow from all
    <Directory>
</VirtualHost>

Now it's working.

liewl
  • 207
  • 1
  • 9

3 Answers3

2

Grep for DocumentRoot in your other conf files, like httpd.conf - is it defined anywhere outside of your vhosts? It's unclear from your question and the followups if your default DocumentRoot is actually in /var/www. You could have a different DocumentRoot pointing at an entirely different directory tree that's not /var/www - in which case changing permissions on /var/www won't affect anything.

Also when you say 'access files on the webroot' what do you mean exactly? How are you accessing the files?

Phil Hollenback
  • 14,647
  • 4
  • 34
  • 51
  • Well, I looked into httpd.conf and there's a line with 'DocumentRoot "/srv/httpd/htdocs"' in it. /srv/httpd is a symbolic link to /var/www. On httpd-vhosts.conf there's a 'DocumentRoot /var/www' on the first vhost definition. I tried commenting out each one of them at a time, but no luck. I also tried to change httpd-vhosts.conf with 'DocumentRoot /var/www/htdocs' instead, but also no luck. I'm not forgetting to restart apache after every change, by the way. – liewl Jan 23 '11 at 14:33
  • What I meant with 'access files on the webroot' is trying to open files with a browser, by typing 'localhost/somefile.html' on the address bar. – liewl Jan 23 '11 at 14:34
  • ok so change your default DocumentRoot from /srv/httpd/htdocs to some other real directory different than /var/www, put an index.html in it, restart your apache, and see if you can then retrieve that docuemnt. – Phil Hollenback Jan 23 '11 at 19:38
  • It worked! I changed to /tmp/wwwtest, and it displayed index.html correctly. Now here's what's weird. I went back to httpd.conf and reverted the changes, and now the old webroot is working again! I think I'll never know what went wrong. – liewl Jan 24 '11 at 00:30
  • Glad to help. Please accept mine or another of the answers. Also please upvote any answers which were useful. – Phil Hollenback Jan 24 '11 at 00:33
1

Did you do

Chown -R www-data:www-data /var/www

Make sure the user that apache is running as has permission to access /var/www

Hope that helps, RayQuang

RayQuang
  • 664
  • 1
  • 9
  • 16
  • I don't have a user or group named www-data, but I do have a user and a group named apache. I ran that command but with user and group apache, but the problem persists – liewl Jan 23 '11 at 04:04
1

Do you have a default document defined anywhere? If that's missing or doesn't include the filename you're using as your default a 403 is often returned.

squillman
  • 37,618
  • 10
  • 90
  • 145
  • What document are you referring to? – liewl Jan 23 '11 at 04:01
  • The file that would be returned if the requested URI was only like http://mysite.com instead of http://mysite.com/myfile.html. Apache uses the DirectoryIndex directive to define the site's list of default documents. http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex – squillman Jan 23 '11 at 04:04
  • I have DirectoryIndex index.html index.php on my httpd.conf, but I also get a 403 when I try to access them. – liewl Jan 23 '11 at 04:23
  • Ok, then you should check out the permissions on your doc root and subdirectories like RayQuang mentioned in his answer. – squillman Jan 23 '11 at 04:24
  • I just ran chmod -R 777 /var/www . The problem is still there. This setup of mine was working before, I don't even remember messing with the configuration files before this problem arised. – liewl Jan 23 '11 at 04:33