Apr 17, 2011

f Comment

Fixing 403 Errors When You Go To Your Website's Document Root!

Amazon If your website is not configured correctly you may see 403 errors when you go to your website's homepage. If your web server is Nginx you should see the following screenshot.

403 Forbidden



nginx/0.6.32

And you see the following screenshot if your web server is Apache:

Forbidden

You don't have permission to access / on this server.


SOLUTION
And you wonder WHY?? The answer is easy. You need to configure your web server to do two things:

1. Allow access to the document root.
2. Specify what file or script to run when document root is accessed.

If you are using Apache and the web root is C:\repository\trunk-php, then the following configuration is an example of allowing access to your document root (placed in httpd.conf):

<directory "C:\repository\trunk-php">
...
Allow from all
...
</Directory>

<IfModule dir_module>
DirectoryIndex index.php
</IfModule>

You'll have to go through Apache's tutorial to find exactly how the configuration works, but the above configuration basically says everyone is allowed to access C:\repository\trunk-php via whatever reachable name. For example suppose your website can be reached by 127.0.0.1 and 192.168.0.33 and http://www.yourdomain.com. This configuration makes your site accessible by all of them. When you do go to www.yourdomain.com you'll see C:\repository\trunk-php\index.php as the 2nd part of the configuration suggests.

If you are using Nginx the configuration may look something like this:

server {
  listen  80;
  server_name  www.yourdomain.com;
  ...
  location / {
    root /home/repository/trunk-php/;
    index index.php
    allow all;
  }
}

This configuration means when you go to www.yourdomain.com you'll see /home/repository/trunk-php/index.php served and 'allow all' means it's accessible from all reachable names.

Errors In The Log
By the way you can also see the 403 errors reflected in your log. In Nginx's log you'd see:

2011/03/08 14:40:59 [error] 7659#0: *1 directory index of "/home/repository/trunk-php/" is forbidden, client: 61.0.0.0, server: www.yourdomain.com, request: "GET / HTTP/1.1", host: "www.yourdomain.com"
In Apache's log you'd see:

[Tue Mar 08 23:17:25 2011] [error] [client 127.0.0.1] Directory index forbidden by Options directive: C:/repository/trunk-php/
Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael