{"id":17307,"date":"2023-07-05T11:41:56","date_gmt":"2023-07-05T11:41:56","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=17307"},"modified":"2023-07-20T09:44:17","modified_gmt":"2023-07-20T09:44:17","slug":"how-to-install-and-configure-squid-proxy-server-for-private-connections-on-centos","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-configure-squid-proxy-server-for-private-connections-on-centos\/","title":{"rendered":"How to Install and Configure Squid Proxy Server for Private Connections on CentOS"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1024x768.jpg\" alt=\"How to Install and Configure Squid Proxy Server for Private Connections on CentOS\" width=\"1024\" height=\"768\" class=\"alignnone size-large wp-image-17308 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1024x768.jpg 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-300x225.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1536x1152.jpg 1536w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-2048x1536.jpg 2048w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-128x96.jpg 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-420x315.jpg 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-540x405.jpg 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-720x540.jpg 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-960x720.jpg 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1140x855.jpg 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1320x990.jpg 1320w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Install-and-Configure-Squid-Proxy-Server-for-Private-Connections-on-CentOS-1440x1080.jpg 1440w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/768;\" \/><\/p>\n<p>As server administrators and webmasters, we are often faced with the challenge of ensuring our connections remain private and secure. One solution to this problem is the use of a <a href=\"https:\/\/webhostinggeeks.com\/blog\/proxy-server-definition-functionality-types\/\">proxy server<\/a>. A proxy server acts as an intermediary between your server and the internet, providing an additional layer of security and privacy.<\/p>\n<p>One of the most <a href=\"https:\/\/webhostinggeeks.com\/best\/proxy-servers\/\">popular proxy server<\/a> software is <a href=\"https:\/\/webhostinggeeks.com\/blog\/squid-proxy-server-features-functions-benefits\/\">Squid<\/a>. Squid is a highly flexible, widely-used, caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages.<\/p>\n<p>In this tutorial, we will guide you through the process of setting up Squid Proxy on a CentOS server. This setup will allow you to establish private connections, enhancing your security and privacy while online. Whether you&#8217;re using a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS<\/a>, or <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a> machine, this guide will be applicable.<\/p>\n<p>By the end of this tutorial, you will have a fully functional Squid Proxy server ready to use. This will not only enhance your server&#8217;s security but also improve its performance by caching and reusing frequently-requested web pages. <\/p>\n<p>So, let&#8217;s dive in and start setting up your Squid Proxy for private connections on CentOS.<\/p>\n<h2>Step 1: Update Your System<\/h2>\n<p>The first step in setting up Squid Proxy on CentOS is to ensure that your system is up to date. This can be done by running the following command:<\/p>\n<pre>\r\nsudo yum update -y\r\n<\/pre>\n<p>This command will update all the packages on your CentOS system to their latest versions.<\/p>\n<h2>Step 2: Install Squid<\/h2>\n<p>Once your system is up to date, the next step is to install Squid. This can be done by running the following command:<\/p>\n<pre>\r\nsudo yum install squid -y\r\n<\/pre>\n<p>This command will install Squid on your CentOS system.<\/p>\n<h2>Step 3: Configure Squid<\/h2>\n<p>After installing Squid, the next step is to configure it. This involves editing the Squid configuration file, which is located at \/etc\/squid\/squid.conf. You can open this file in a text editor by running the following command:<\/p>\n<pre>\r\nsudo nano \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>In the configuration file, you can specify the settings for your Squid Proxy server. For example, you can specify the port that Squid listens on, the maximum object size that can be cached, and the access control lists (ACLs) that determine who can access the proxy server.<\/p>\n<p>Once you have made the necessary changes to the configuration file, save and close the file.<\/p>\n<h2>Step 4: Start and Enable Squid<\/h2>\n<p>After configuring Squid, the next step is to start the Squid service and enable it to start on boot. This can be done by running the following commands:<\/p>\n<pre>\r\nsudo systemctl start squid\r\nsudo systemctl enable squid\r\n<\/pre>\n<p>These commands will start the Squid service and enable it to start on boot.<\/p>\n<h2>Step 5: Verify Squid Installation<\/h2>\n<p>The final step in setting up Squid Proxy on CentOS is to verify that the installation was successful. This can be done by checking the status of the Squid service. Run the following command:<\/p>\n<pre>\r\nsudo systemctl status squid\r\n<\/pre>\n<p>If Squid has been installed and configured correctly, you should see an output indicating that the Squid service is active and running.<\/p>\n<h2>Squid Configuration Examples<\/h2>\n<p>Here are some examples of how you can configure Squid for different purposes:<\/p>\n<h3>1. Blocking Specific Websites<\/h3>\n<p>To block specific websites, you can add the following lines to your Squid configuration file:<\/p>\n<pre>\r\nacl blocked_websites dstdomain .facebook.com .youtube.com\r\nhttp_access deny blocked_websites\r\n<\/pre>\n<p>This will block access to Facebook and YouTube.<\/p>\n<h3>2. Allowing Specific Websites Only<\/h3>\n<p>If you want to allow access to only specific websites, you can use the following configuration:<\/p>\n<pre>\r\nacl allowed_websites dstdomain .google.com .wikipedia.org\r\nhttp_access deny all\r\nhttp_access allow allowed_websites\r\n<\/pre>\n<p>This will only allow access to Google and Wikipedia, and deny all other websites.<\/p>\n<h3>3. Setting Up a Transparent Proxy<\/h3>\n<p>To set up a transparent proxy, add the following line to your Squid configuration file:<\/p>\n<pre>\r\nhttp_port 3128 transparent\r\n<\/pre>\n<p>This will set up Squid as a transparent proxy on port 3128.<\/p>\n<h3>4. Limiting Access to Specific IP Addresses<\/h3>\n<p>To limit access to specific IP addresses, use the following configuration:<\/p>\n<pre>\r\nacl allowed_ips src 192.168.1.0\/24\r\nhttp_access deny all\r\nhttp_access allow allowed_ips\r\n<\/pre>\n<p>This will only allow access to the IP addresses in the range 192.168.1.0 to 192.168.1.255.<\/p>\n<h3>5. Setting Up a Cache<\/h3>\n<p>To set up a cache, add the following lines to your Squid configuration file:<\/p>\n<pre>\r\ncache_dir ufs \/var\/spool\/squid 100 16 256\r\n<\/pre>\n<p>This will set up a cache directory at \/var\/spool\/squid with a maximum size of 100 MB.<\/p>\n<h3>6. Logging Access<\/h3>\n<p>To log access, use the following configuration:<\/p>\n<pre>\r\naccess_log \/var\/log\/squid\/access.log squid\r\n<\/pre>\n<p>This will log all access to \/var\/log\/squid\/access.log.<\/p>\n<h3>7. Disabling Caching<\/h3>\n<p>To disable caching, add the following lines to your Squid configuration file:<\/p>\n<pre>\r\ncache deny all\r\n<\/pre>\n<p>This will disable all caching.<\/p>\n<h3>8. Setting Up a Parent Proxy<\/h3>\n<p>To set up a parent proxy, use the following configuration:<\/p>\n<pre>\r\ncache_peer parentproxy.example.com parent 3128 0 no-query default\r\n<\/pre>\n<p>This will set up a parent proxy at parentproxy.example.com on port 3128.<\/p>\n<h3>9. Restricting Access by Time<\/h3>\n<p>To restrict access by time, use the following configuration:<\/p>\n<pre>\r\nacl work_hours time M T W T F 9:00-17:00\r\nhttp_access deny all\r\nhttp_access allow work_hours\r\n<\/pre>\n<p>This will only allow access during work hours (Monday to Friday, 9:00 to 17:00).<\/p>\n<h3>10. Setting Up Authentication<\/h3>\n<p>To set up authentication, add the following lines to your Squid configuration file:<\/p>\n<pre>\r\nauth_param basic program \/usr\/lib\/squid\/basic_ncsa_auth \/etc\/squid\/passwords\r\nauth_param basic children 5\r\nauth_param basic realm Squid proxy-caching web server\r\nauth_param basic credentialsttl 2 hours\r\nacl auth_users proxy_auth REQUIRED\r\nhttp_access deny all\r\nhttp_access allow auth_users\r\n<\/pre>\n<p>This will set up basic authentication with the usernames and passwords stored in \/etc\/squid\/passwords.<\/p>\n<h3>11. Blocking Specific File Types<\/h3>\n<p>To block specific file types, use the following configuration:<\/p>\n<pre>\r\nacl blocked_files urlpath_regex .exe$ .mp3$ .torrent$\r\nhttp_access deny blocked_files\r\n<\/pre>\n<p>This will block access to .exe, .mp3, and .torrent files.<\/p>\n<h3>12. Redirecting URLs<\/h3>\n<p>To redirect URLs, you can use the url_rewrite_program directive:<\/p>\n<pre>\r\nurl_rewrite_program \/usr\/bin\/redirect_script\r\n<\/pre>\n<p>This will redirect URLs based on the rules defined in the \/usr\/bin\/redirect_script.<\/p>\n<h3>13. Enabling SSL Bump<\/h3>\n<p>To enable SSL Bump, add the following lines to your Squid configuration file:<\/p>\n<pre>\r\nhttp_port 3128 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=\/etc\/squid\/ssl_cert\/myCA.pem\r\nssl_bump allow all\r\n<\/pre>\n<p>This will enable SSL Bump on port 3128 with the certificate located at \/etc\/squid\/ssl_cert\/myCA.pem.<\/p>\n<h3>14. Setting Up a Reverse Proxy<\/h3>\n<p>To set up a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-reverse-proxy\/\">reverse proxy<\/a>, use the following configuration:<\/p>\n<pre>\r\nhttp_port 80 accel defaultsite=www.example.com vhost\r\ncache_peer 192.168.1.10 parent 80 0 no-query originserver name=myAccel\r\nacl our_sites dstdomain www.example.com\r\nhttp_access allow our_sites\r\ncache_peer_access myAccel allow our_sites\r\n<\/pre>\n<p>This will set up a reverse proxy for www.example.com.<\/p>\n<h3>15. Limiting Download Size<\/h3>\n<p>To limit the download size, use the following configuration:<\/p>\n<pre>\r\nreply_body_max_size 50 MB\r\n<\/pre>\n<p>This will limit the maximum download size to 50 MB.<\/p>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">yum install squid<\/span> \u2013 Installs the Squid proxy server on CentOS.<\/li>\n<li><span class=\"fw-bold\">systemctl start squid<\/span> \u2013 Starts the Squid service.<\/li>\n<li><span class=\"fw-bold\">systemctl enable squid<\/span> \u2013 Enables the Squid service to start on boot.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Setting up Squid for private connections on CentOS adds an additional layer of security and privacy for your server&#8217;s internet connections.<\/p>\n<p>Remember, the key to maintaining a secure and efficient server is regular updates and monitoring. Always keep your system and software up-to-date, and monitor your server&#8217;s performance regularly to ensure it&#8217;s running at its best. <\/p>\n<p>Hope you found this tutorial helpful.<\/p>\n<p>If you have any questions or run into any issues, feel free to leave a comment below.<\/p>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is Squid Proxy Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">Squid is a caching and forwarding HTTP web proxy that supports HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why use Squid Proxy Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">Squid Proxy Server improves performance by caching and reusing frequently-requested web pages. It also provides security as it can limit the web access for certain users and hide users&#8217; IP address.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How to install Squid Proxy Server on CentOS?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">You can install Squid on CentOS using the command &#8216;yum install squid&#8217;. After the installation, start the service with &#8216;systemctl start squid&#8217; and enable it to start on boot with &#8216;systemctl enable squid&#8217;.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How to configure Squid Proxy Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">Squid Proxy Server can be configured by editing the Squid configuration file located at \/etc\/squid\/squid.conf. You can define access control lists, set up caching parameters, and more.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the difference between Squid Proxy Server and Apache HTTP Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">Squid is primarily a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. On the other hand, Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.<\/span>\n<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>As server administrators and webmasters, we are often faced with the challenge of ensuring our connections remain private and secure. One solution to this problem is the use of a&#8230;<\/p>\n","protected":false},"author":6,"featured_media":17308,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1057],"tags":[1244,2089,1975,1678,1793],"class_list":["post-17307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-squid-server","tag-centos","tag-configuration","tag-install","tag-proxy","tag-squid"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/17307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=17307"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/17307\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/17308"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=17307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=17307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=17307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}