View Full Version : Guide:Setup Squid as a HTTP proxy on your VPS to browse blocked web sites!
Ruchirablog 01-05-2011, 11:18 AM I have tried many proxy methods such as D switch on SSH,web based proxies,VPN and all the methods are slow than average browsing because encryption etc.
But I have tried setting up squid to test and I have experienced it gives that same speed like without any proxy. ( also you need to have a good VPS or dedi to get the speed)
And now I dont need to consider going back to no proxy because squid delivers content to my PC as fast as no proxy.
So here is my guide to setup squid on ubuntu or debian vps for you. You can even run it on 64MB RAM VPS but needs good connection to get no-proxy speeds from it! :)
What you will need-
* A VPS or dedicated server with minimum ram of 64MB (64MB of ram will be enough because squid doesn’t eat much ram)
* Debian or Ubuntu installed on your server
* NANO text editor installed on your server ( run “apt-get install nano” to install it if you dont have it already)
Steps-
Install squid on your ubuntu or debian server, issue this command over SSH
apt-get install squid
Then squid is successfully installed and you need to setup squid to access internet because its currently set only for localhost
squid’s config file is huge so we need to find some lines using nano on squid config file.
Issue this commands to open squid config file with NANO text editor.
nano /etc/squid/squid.conf
18159
squid config Setup Squid as a HTTP proxy to browse blocked web sites!
On there we need to add 2 lines to configure this for our personal use.
You can add then on top of the page. those 2 lines are
http_access allow all
http_access allow localnet
Here is the squid.conf file after adding that 2 lines
18158
squid modified conf Setup Squid as a HTTP proxy to browse blocked web sites!
So that’s it on server side. Restart squid to load our configuration.
restart squid
Like I said previously on this guide I’m not focused on setting up security for squid like adding ACL (Access Control Lists) to prevent other users using your proxy etc.
But this is 1000 times better than setting up a php web based proxy to browse the web.
While server side setup complete we need to setup our web browsers to use our proxy. I think you are probably using firefox to browse the web so here is the configuration for firefox for other programs you can use the same.
On firefox navigate to Tools=>Options=>Advanced=>Network=>Settings=>Manual Proxy Configuration
On that page enter your IP address that squid is installed and port as 3128 because we didn’t changed the default squid port. Also click the checkbox “Use this proxy server for all protocols”
firefox settings Setup Squid as a HTTP proxy to browse blocked web sites!
18157
Thats it! icon smile Setup Squid as a HTTP proxy to browse blocked web sites!
Note that
* We didn’t setup Access Control Lists so any one who knows your squid server ip address and port can use your proxy.
* When choosing a server for setting up squid for your use try to get a server which gives lowest ping times for your location which will help you to browse more fast.
Here is the link for original post! - http://www.ruchirablog.com/setup-squid-as-http-proxy-to-view-blocked-web-sites/
SerayaHost 01-05-2011, 11:36 AM Very nice guide..
Will try to do that on my vps..
Thanks...
dyna! 01-05-2011, 12:52 PM Without...
Like I said previously on this guide I’m not focused on setting up security for squid like adding ACL (Access Control Lists) to prevent other users using your proxy etc....not only is this generally a bad idea, but is against the ToS of a lot of hosts that post here.
Ruchirablog 01-05-2011, 12:59 PM Without...
...not only is this generally a bad idea, but is against the ToS of a lot of hosts that post here.
No I dont think hosts wont allow personal proxies. Actually its not good idea to run this kind of proxy for public because it will degrade performance and use bandwidth a lot than web based proxy.
So this article is generally for Private use proxy!
netroby 01-05-2011, 08:23 PM Thank you for share us the good tutorial , but if you want to browse blocked web sites, you may choice SSH Tunnel first . it is fast and security.
mattdahack 01-06-2011, 11:42 PM Adding an access control list is only a couple more lines and definitely worth adding. All the vps hosts that I have had on here don't care if you run a SQUID proxy as long as it's not public. This said, your proxy will be found if it's running on the default port. There are people all day that scan massive ranges of ip's looking for proxies to do their dirty work with.
Now for the good stuff. To add to these diretions an ACL (access control list) we can do two things. Make an ACL that allows only shell users. AKA people that we (adduser joesmoe) to our vps, or use an ACL with a passwd file that is in the same directory as the squid.conf file. It took me a while to figure out but it's definitely worth it.
I like adding users via the passwd file because you don't have to give users access to your vps in order for them to use the proxy....YES, I know you can specifiy no shell access at the time of the user creation to get by this conundrum. But that is too much stuff to get into for this simple add on tutorial.
Ok so lets build on this previous tutorial.
To add system users with vps access to the proxy access add this to the top of your conf.
#1
nano /etc/squid/squid.conf
#2
#Insert the below text into your config file
#Custom Modifications
auth_param basic program /usr/lib/squid/pam_auth
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 4 hours
acl password proxy_auth REQUIRED
http_access allow password
#3
#Use the find command to locate port 3128 (CTRL + W) 3128
#Change port 3128 to something else
http_port 9988
#4
#Let's also add this
# This will stop your http proxy from forwarding your headers from your real IP.
forwarded_for off
#5
# And finally deny all other access to this proxy except for vps shell users.
http_access deny all
#6
#next save your new config ( CTRL + O ) , then ( CTRL + X )
#7
#Now we have to stop squid and restart with the newly edited config file for changes to take place.
#8
#Change your prompt to the PWD /etc/squid/
squid -k shutdown
squid squid.conf
#9 Now set your browser to use your newly designated port.
# When your done load a new webpage and you should get a prompt for a user name and password. BAM. Enter your credentials and you're on your way.
------------------------------------------------------------
ALTERNATIVE METHOD
------------------------------------------------------------
If your like me and you don't want your proxy users to have access to your vps, then make a simple access file in your /etc/squid/ directory called users_passwd.
Follow the Step by step below to have squid use this file instead of PAM to authenticate your users.
#1
nano /etc/squid/users_passwd
type any character press backspace and save an empty file.
exit nano
#2
nano /etc/squid/squid.conf
#add this to the top of your config file
# Custom commands
#turn off http headers being forwarded
forwarded_for off
#As you can see below, the proxy will authenticate your users
#with ncsa auth using the file we just made called users_passwd
#located in the /etc/squid/ directory.
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/users_passwd
#now we are going to have to make the proxy autheicate your users. Add this next line below the previous.
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
#3
# Add this last line to protect your proxy
# And finally deny all other access to this proxy
http_access deny all
# If you want to change the port as above just search for 3128 (ctrl + w).
#Change port 3128 to something else
#http_port 9988 or whatever you want
#4
# Now save your newly modifies config file. ( CTRL + O )
#5
# Exit nano (ctrl + x)
#6
#shutdown squid from PWD (/etc/squid) squid -k shutdown
#7
#now we are going to make our first new user to go in our #users_passwd file located /etc/squid/users_passwd. To do this we are going to use the htpasswd program that comes with apache2
#If you have apache2 installed great if not you need to get htpasswd from somewhere.
#8
# Let's generate our first user.
htpasswd /etc/squid/users_passwd your-first-user-name-here
#9
#Enter the password you want for your-first-user-name-here
#10
#verify that the user was added to the users file.
nano /etc/squid/users_passwd
# You should see your first username: followed by an encrypted password.
# Now exit out of nano and let's start up squid to test your first user name.
#11
# From the PWD /etc/squid/
squid squid.conf
#12
# Now open a web browser with your custom port and Ip set in the proxy configuration options. If you did this right, you should be prompted for a username and password. Enter what you made a few minutes ago for the username and the password you chose. If you did it all correctly you should see your web page come up.
Hope this helps anyone who was having difficulty setting this program up. I know I struggled when I initally installed this program until I got it simplified. Let me know if anyone needs any help setting this up and I will try to assist you.
--Matt
Ruchirablog 01-07-2011, 04:01 AM Thanks for the follow up :) . But its easy if we just add ACL for ip range block! Allowing only our subnet (for users who have dynamic ip) or limiting access only for our ip (users who got dedicated ip from ISP)
How ever thanks again for followup! :D
jfreak53 02-20-2011, 08:17 PM Quick question on this. I am going to be setting up a Squid proxy for my personal use this next week or so. This tutorial is just what I was looking for. But one thing, what do I need to add to limit day and time for a user, well better yet for a group and assign users to a group if possible?
I need to have two groups for my small set of users, one is mon-fri, 8AM-5PM and the other group is only Sat 8-5.
Thanks for any help you can give me. I tried the Squid wiki but man is it a mess to understand.
mattdahack 02-21-2011, 11:31 PM So you want to know how you can allow some clients to use the cache at specific times?
Let's say you have two users that should only be allowed access to the Internet during working hours (8:30 - 17:30). You can use something like this:
acl RESTRICTIONS USER1 # Replace with proxy username
acl WORKING time MTWHF 08:30-17:30 # Times to allow access in 24hour format
http_access allow RESTRICTIONS WORKING
http_access deny RESTRICTIONS
bsdvps 02-21-2011, 11:49 PM How about username / password authorization?
mattdahack 02-22-2011, 12:18 AM Use this below code for everything
acl WORK_TIME time MTWHF 08:30-17:30 # Time allowed access in 24hour format
http_access allow ncsa_restricted_time_users WORK_TIME
http_access deny ncsa_restricted_time_users
acl ncsa_restricted_time_users proxy_auth REQUIRED
http_access allow ncsa_restricted_time_users
http_access deny all
Then make a new user file and put the people in it you want restricted
to the above specified times. Call the file 'ncsa_restricted_time_users'
without the quotes and put it in the same directory as the config file
to generate a new restricted user in your new file use the following command
htpasswd /etc/squid/ncsa_restricted_time_users user1
bsdvps 02-22-2011, 12:22 AM Thanks. I may have overlooked it but the caffeine is wearing off and bed is looking very comfortable.
jfreak53 02-28-2011, 03:12 PM Hmm I am getting an error:
ACL name 'ncsa_restricted_time_users' not defined!
FATAL: Bungled squid.conf line 6: http_access allow ncsa_restricted_time_users WORK_TIME
Squid Cache (Version 2.6.STABLE21): Terminated abnormally.
This is the top of my squid.conf file:
acl WORK_TIME time A 08:00-17:00 # Time allowed access in 24hour format
http_access allow ncsa_restricted_time_users WORK_TIME
http_access deny ncsa_restricted_time_users
acl ncsa_restricted_time_users proxy_auth REQUIRED
http_access allow ncsa_restricted_time_users
http_access deny all
# WELCOME TO SQUID 2.6.STABLE21
I have created the pass file so that's there, what did I break this time ha ha
jfreak53 02-28-2011, 04:28 PM Never mind we're good I moved things around a bit and now it works. Thanks for the help.
mattdahack 02-28-2011, 05:19 PM Glad to be of service. Glad to hear you got it working :-)
jfreak53 03-01-2011, 08:45 AM Ok, hate to be a pain, but it works but it's extremely slow. I know it's not that server since I use that server for backups and it's connection speed is always transfer between two servers at around 8 or 9 MB/s. I mean it takes about 30 seconds to load Google. What could this be?
mattdahack 03-01-2011, 09:36 PM I don't know man, mine runs great Getting about 6mb/sec through the proxy. I am not sure what is going on with your's check your firewall rules and if you're running one, shut it down and restest the speed.
Deroba 03-01-2011, 09:45 PM Nice guide, anyway to optimize is really good with cache?
evildon 03-04-2011, 12:13 AM Really cool guide..
Helped me out while installing it for a client of mine :)
Thanks
jfreak53 03-05-2011, 08:46 AM Well it's working now wonderfully, I messed around with some cache settings and we're all good. Quick one more question before I go messing with the file to figure it out. Is there a way to have two user groups and different times and such? For instance, I want one user group to be filtered by the times I set, that works great. But I have one user that I want to give access to whenever they login, is this possible?
eric6630 04-25-2011, 04:22 AM does anyone knows how to resolve this issue?
im using centOS
[root@tiger ~]# chkconfig squid on
[root@tiger ~]# service squid start
init_cache_dir /var/spool/squid... /etc/init.d/squid: line 62: 3133 Aborted $SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
Starting squid: /etc/init.d/squid: line 42: 3134 Aborted $SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
[FAILED]
[root@tiger ~]#
phoneplus 05-05-2011, 08:38 PM Sorry for updating an old thread, but how do you exit from squid.conf file after you edit it. I spent 30 minutes trying to figure it out, if someone could help me, it would be greatly appreciated.
Ruchirablog 05-05-2011, 11:29 PM Sorry for updating an old thread, but how do you exit from squid.conf file after you edit it. I spent 30 minutes trying to figure it out, if someone could help me, it would be greatly appreciated.
Ctrl+O to write the changes!
Ctrl+X to exit!
eric6630 05-05-2011, 11:41 PM how can i access any site using squid?
every time i go visit a site it always "denied" is there anything i can do to resolve the said issue?
thank you
n3rdy-jenn 05-11-2011, 02:41 PM Anyone got a link to a manual describing how to block certain ad servers via Squid. For instance, when I surf facebook or myspace using squid....sometimes there are giant flash/image ads, that slow me down big time. How can I go in squid & block like "serv21.adserver.valueclick.com"? I haven't figured out where to put it in the config & it's been like 2 years I've used squid now lol
raininglemons 05-11-2011, 02:44 PM Anyone got a link to a manual describing how to block certain ad servers via Squid. For instance, when I surf facebook or myspace using squid....sometimes there are giant flash/image ads, that slow me down big time. How can I go in squid & block like "serv21.adserver.valueclick.com"? I haven't figured out where to put it in the config & it's been like 2 years I've used squid now lol
Blacklist the domains you don't want with dstdomain and acl's;
eg. http://www.screaming-penguin.com/node/3871
Lux Newbie 05-18-2011, 11:44 PM Nice tutorial :D. But, I think, if you have a Linux server/VPS. You can make a tunel and browse blocked website very good.
Thanks
xs-admin 06-16-2011, 11:15 AM I am going to try it. I hope it'll work like mentioned here.
SimplexHosting 06-26-2011, 12:32 PM That was sooo usefull. Thanks I recently bought a vps too
David998 10-20-2011, 09:33 AM Hi, thanks so much for providing those informations ;)
and especially mattdahack for the good config options !
I'm in Canada, and as i am a web developer i want to access french websites as if i was geolocalised in France..
So i installed SQUID on one of my french located server.
It works good on many websites with mattdahack advices!
But some websites still know i'm not in FRANCE !!!
Here's my changes to Squid config :
acl canada_macdev src here.is.my.ip/255.255.255.0
http_access allow canada_macdev
http_port 9874
forwarded_for off
I know that HideMyAss VPN use the same web server company in France than me and with them it works ok..
The issue i noticed is with SilverLight streaming player, maybe Silverlight act differently than http ?
mattdahack 10-21-2011, 12:24 AM If you double check my instructions(maybe you missed it) I have that forwarded_for off under item #4 :-). Glad to know it's working though thanks :)
kang_kutu 11-24-2011, 09:20 PM nice guide, I used squid 3 and it works like wonder :D
mouth 01-23-2012, 08:25 AM Excellent stuff. Thanks, just implemented this on my server in around 15mins. Also helps with USA sites seeing you as a local resident from geo IP :)
technichristian 02-07-2012, 07:12 AM Thanks for this lovely tutorial. The one problem I have when using Squid - Java applets don't work. All java applets fail to initialize.
Is there a solution to this?
Erawan Arif Nugroho 03-07-2012, 12:36 AM Is there any tutorial for working with IPv6?
machoman 03-21-2012, 07:23 PM What server will allow me to do this? I want to try this asap!!
machoman 03-21-2012, 10:39 PM I am willing to pay someone a reasonable amount if they help me set this up and teach me how to use it/ maintain it.
anyone?
andri 03-28-2012, 08:18 AM Thank you Ruchira and Matt! This one's working very well. :)
Erawan Arif Nugroho 04-01-2012, 07:17 PM Just an update :
I have a BuyVM VPS, and I'm running Debian 6 with Squid3.1
It can open an IPv6 website
moloch 04-02-2012, 11:00 AM Hello
For those who are familiar with linux this guide should be very easy to follow but for those that take the first steps in linux parts of the guide are as "chinese".
What I needed was a step by step guide for dummies...
I need to create a private proxy server on a VPS to view restrict geographic content.
I got a free trial of a Cloud VPS from ElasticHost and I'm using the TightVNC to access my VPS running Ubuntu 10.04LTS but the only thing I can do is install the squid with the command "apt-get install squid" then I can still enter the squid.conf file but going forward I do not know what to do.
The guide says to "add this line","add that line" but does not say HOW to add.
I've tried to follow other guides and install CentOS or Debian on my VPS and then tried tinyproxy server but without success :(
Someone can help me create my private proxy?? with a step by step for dummies easy to follow??
Thanks
(Sorry for my bad english, I'm from Portugal.)
moloch 04-02-2012, 05:38 PM After following again the "ALTERNATIVE METHOD" the proxy was working and ask for password but I had to remove the following command:
http_access deny all
With this line squid always gives error. What can I do to solve this problem? I am using a Cloud VPS running Ubuntu 11.
Thanks
|