Minggu, 17 April 2011

Fix 403 Error When You Go To Your Website's Web or Document Root

Q: How do you fix 403 error when you go to your website's homepage?

For example suppose your website is http://www.mensfashionforless.com/ but when you go there you see something like the following if your web server is Nginx:

403 Forbidden



nginx/0.6.32


And you see the following 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 if your website can be reached by 127.0.0.1, 192.168.0.33, www.mensfashionforless.com this configuration makes your site accessible by all of them. When you do go to www.mensfashionforless.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.mensfashionforless.com;
...
location / {
root /home/repository/trunk-php/;
index index.php
allow all;
}
}


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

Error Reflected In The Log
By the way you can also see the 403 error reflected in your log. In nginx 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.218.81.34, server: www.mensfashionforless.com, request: "GET / HTTP/1.1", host: "www.mensfashionforless.com"

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

0 komentar:

 
support by: infomediaku.com