Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, September 2, 2013

How to set up a simple proxy server on Digital Ocean/ VPS

SSH in to your digital ocean droplet and run the following

sudo apt-get install tinyproxy #install tinyproxy
which tinyproxy # make sure tinyproxy is installed
ps -ef | grep proxy # make sure tinyproxy is running

Now forward a port from your server/machine to the remote proxy on the droplet
ssh -N root@dro.ple.tip.xxx -L local_port:localhost:remote_port
e.g. ssh -N root@198.199.xxx.xxx -L 8000:localhost:8888

Send a request to localhost at port 8000 and see if it appears in the tinyproxy logs. If you are using ruby to do crawling/scraping on websites you can set proxy on the agent:

agent.set_proxy localhost, 8000agent.get("somewebsite")

See the results on your droplet appear in:
/var/log/tinyproxy.log

Create a Simple HTTP Server on a directory to bypass same origin policy


Let's say you are doing development of a website that uses Javascript on your laptop. Often you will notice that you will run in to issues where the browser does not allow you to access certain resource because of the same origin policy. Also, often at times you are working on a bunch of HTML files and want to host a few files over HTTP.

You can do it quickly by creating a simple HTTP server that will open access to all files in the directory over HTTP. Here's the nifty python command that does that:

python -m SimpleHTTPServer 8900

Where 8900 is the port you want the content to be hosted upon.