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!

Issues with Sphinx Search Engine Wordforms

Q: How come sometimes Sphinx search engine's index does not obey the rules I put in wordforms configurations?

To give you more context Sphinx is an open-source SQL full-text search engine. Wordforms is a functionality it provides where you can specify synonyms so that your index covers them. For example suppose your index contains documents that contain the word 't-shirt' and you also want them to be matched when the search keyword is 'tshirt'. Without setting up such synonym mapping in Sphinx, Sphinx wouldn't know 't-shirt' and 'tshirt' mean the same thing. Once you set the configuration accordingly Sphinx will get you the desired search results.

Sometimes I run into the problem where I define the mapping, rebuild Sphinx index, rerun Sphinx search daemon, but still fail to have Sphinx recognize the new mapping I put in. If this happens to you simply insert a new line at the end of the configuration file, or reorder the mappings. For example if your original mapping is the following:

mockneck > mock neck
ae > american eagle
peacoat > pea coat
slitneck > slit neck


Reorder them to the following:

mockneck > mock neck
slitneck > slit neck
ae > american eagle
peacoat > pea coat


Rebuilt Sphinx index, rerun search daemon, and try querying your index again. Hope this helps! By the way this fix applies to other configuration for Sphinx as well such as Stopwords. If you run into similar problems with other kinds of configuration try the same fix! Questions? Let me know!
 
support by: infomediaku.com