This is a script that act as proxy between your web browser and some domaines of your choice. Whenever your webbrowser request a page in one of these domains the script download the page, cache it and then return it to your browser. future requests to the same page will be returned from the offline cache.
- Conserve bandwidth when frequently accessing a site with a static or semi-static content (ex: documentations of certain version of a software).
- If you are a web developer and want to develop sites offline but unable to because your site(s) require files hosted elsewhere (for example jquery hosted on ajax.googleapis.com)
- Generate a certifcate file
openssl req -new -x509 -nodes -out cert.pem -keyout cert.pem
- Decide what domains you want to cache. lets use ajax.googleapis.com as an example.
- Add the following to your /etc/hosts :
127.0.0.2 ajax.googleapis.com
- Try to access http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js you should get an error
- Create a cache directory, for example
mkdir ~/web_cache
- Run the script as root,
python3 cache_server.py ~/web_cache cert.pem
- Now visit http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js again, it should work
- Visit it again but use https instead of http, naturally you will get certeficate error. say you trust this certeficate.
- Done! Now you can access this url offline.
For adding more domains:
- Add the following to your /etc/hosts :
127.0.0.2 <domain name>
- If you want to support https you must visit any url in this domain and tell the browser to trust the certifcate we generated earlier.
- Done
Note: instead of doing
127.0.0.2 example.com
127.0.0.2 sub.example2.com
You can do
127.0.0.2 example.com sub.example2.com
- The script has to run on port 80 and 443, if you already use this port for apache make sure apache only listen to 127.0.0.1:80 not *:80 same for port 443
- The script support https requests but your webbrowser will complain about invalid certeficate, this is normal because the script is acting as a man in the middle between you and the site you are visiting. in firefox you can say I understand the risks and add an exception
- Some webbrowsers don't bother making http requests when it detect you have no internet connection. To over come this limitation maybe try a different webbrowser or fake internet connection
ifconfig eth0 10.10.0.1 up