LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2012, 02:19 PM   #1
zenith123
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Rep: Reputation: Disabled
configuring cache in apache http server


I am new to the use of apache http server and want to learn its basic administration. To see how cache work in basic form, i did the following:
1)I uncommented
LoadModule cache_module modules/mod_cache.so
LoadModule cache_disk_module modules/mod_cache_disk.so

2)and added this in the httpd.conf file
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot "maya/pkg/apache/cache"
CacheEnable disk /
CacheDirLevels 5
CacheDirLength 3
</IfModule>


3)I created a dir /maya/pkg/apache/cache and set its permission to 777.

4) I restarted the server and opened a page http://localhost/myfolder/sun.html

After doing all this, I was expecting that the content of sun.html will be cached in the maya/pkg/apache/cache folder. But nothing is stored there.

What am i missing???Why is content not being cached??

Sorry, If my question sounds silly.I am just a newbie and want to learn. I would be grateful, If I could get some help on this.

Thanx in advance!!
 
Old 07-02-2012, 02:29 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Quote:
4 HTTP Headers

Caching doesn't work out-of-the-box - you must modify your web application so that caching can work (it is possible that your web application already supports caching - please consult the documentation of your application to find out). mod_cache will cache web pages only if the HTTP headers sent out by your web application tell it to do so.

Here are some examples of headers that tell mod_cache not to cache:

Expires headers with a date in the past: "Expires: Sun, 19 Nov 1978 05:00:00 GMT"
Certain Cache-Control headers: "Cache-Control: no-store, no-cache, must-revalidate" or "Cache-Control: must-revalidate, max-age=0"
Set-Cookie headers: a page will not be cached if a cookie is set.

So if you want mod_cache to cache your pages, modify your application to not send out such headers.
Thats what you're looking for. Apache uses headers for almost everything and it won't do something unless it's told to by a header in most cases.
 
Old 07-02-2012, 02:31 PM   #3
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Try uploading this test.php file to see the results in action. It should load the page the first time with the current timestamp and it should cache that file for 300 seconds and still display the same time as long as you dont force refresh it. ctrl+f5 is a force refresh and tells the server to completely reload it, f5 is a simple refresh and will display the cached page.

PHP Code:
<?php
header
("Cache-Control: must-revalidate, max-age=300");
header("Vary: Accept-Encoding");
echo 
time()."<br>";
?>
 
Old 07-03-2012, 12:12 AM   #4
zenith123
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Kustom42 View Post
Try uploading this test.php file to see the results in action. It should load the page the first time with the current timestamp and it should cache that file for 300 seconds and still display the same time as long as you dont force refresh it. ctrl+f5 is a force refresh and tells the server to completely reload it, f5 is a simple refresh and will display the cached page.

PHP Code:
<?php
header
("Cache-Control: must-revalidate, max-age=300");
header("Vary: Accept-Encoding");
echo 
time()."<br>";
?>

Sorry, but I don't have php installed on my system. I tried to install it, but due to some reason i was not able to properly install it. But I suppose that what you want to suggest is that I should specify the http headers some where.I saw this link:
http://betterexplained.com/articles/...-http-caching/

and so did the following:
1)uncommented LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
in the conf file.

2)added the following code in the httpd.conf file:

<IfModule mod_expires.c>

ExpiresActive On
ExpiresDefault A0

# 1 YEAR - doesn't change often
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
</FilesMatch>


</IfModule>



<filesMatch "\.(html|htm|js|css|pdf)$">

<ifModule mod_headers.c>

Header set Cache-Control "max-age=300"
Header set Vary "Accept-Encoding"
</ifModule>
</filesMatch>


3) Since expire and max age both are specified max age wont be considered and since expire is set to 1 year, so as i thought the pdf document should stay in cache for 1 year.

4) I restarted the server and opened the link localhost/ri/gdsf.pdf. I was again expecting that since I have set the expire header so this thing will be cached the cache root folder that I have specified. But the folder is empty means it has not cached anything.

I want to see how data being cached is stored in the cache root directory..What can I do to see it?????

Last edited by zenith123; 07-03-2012 at 12:41 AM.
 
Old 07-03-2012, 11:14 AM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
You need to specify this on the headers of the page themselves. And in all honesty there really isn't much for you to cash as all of your code looks to be client-side. Caching would only benefit you if you were running PHP or another server-side language that required apache to parse something. At this point your using HTML where Apache simply sends the code as it sits on the server to the client machine and the browser renders the content.

It sound's like you have caching set up but it's not caching anything as there isn't anything it can cache.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
configuring apache to server both http and https for a domain name nkoplm Linux - Server 1 05-06-2012 10:40 PM
A question about configuring Apache Http Server thomas2004ch Linux - Newbie 2 09-11-2009 01:24 AM
Help! Apache Reverseproxy & cache server maheshk78 Linux - General 0 11-16-2006 01:26 AM
Apache HTTP Server gjagadish Programming 1 08-10-2006 09:10 AM
Configuring cache server with BIND Bobbychat Linux - Networking 6 12-26-2003 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration