{"id":504,"date":"2025-06-02T13:15:00","date_gmt":"2025-06-02T13:15:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=504"},"modified":"2025-06-02T13:15:00","modified_gmt":"2025-06-02T13:15:00","slug":"setup-and-configure-proxy-server","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=504","title":{"rendered":"How To Setup and Configures Proxy Server &#8211; Squid Proxy"},"content":{"rendered":"<p>A <a href=\"https:\/\/whatis.techtarget.com\/definition\/proxy-server?ref=devopscube.com\" rel=\"noopener noreferrer\">proxy server<\/a> has many <a href=\"https:\/\/www.digitalcitizen.life\/simple-questions-what-proxy-server-why-would-you-use-one?ref=devopscube.com\" rel=\"noopener noreferrer\">use cases<\/a>. it could range from personal internet access to restrict organization systems\/servers to access the external world or to limit external internet access for a set of servers on the cloud.<\/p>\n<p>The best way to configure a proxy server is by using the Squid proxy. It is a widely used proxy server.<\/p>\n<p>In this article, we have covered the following.<\/p>\n<ol>\n<li>Install Squid Proxy on a Ubuntu server<\/li>\n<li>Configure the proxy server<\/li>\n<li>Configure basic proxy authentication.<\/li>\n<li>Block websites using Squid proxy<\/li>\n<li>Squid Proxy cache<\/li>\n<\/ol>\n<p>Now, we can begin the installation.<\/p>\n<h2 id=\"install-squid-proxy-on-ubuntu\">Install Squid Proxy on Ubuntu<\/h2>\n<p>Follow the steps below to install the latest Squid proxy on a Ubuntu server.<\/p>\n<blockquote><p>Note: For this setup, we use the Ubuntu 24.04 virtual machine.<\/p><\/blockquote>\n<h3 id=\"step-1-install-squid-proxy\"><strong>Step 1:<\/strong> Install Squid<strong> Proxy<\/strong><\/h3>\n<p>Update the package list and install the Squid Proxy, using the following command.<\/p>\n<pre><code class=\"language-bash\">sudo apt update -y\nsudo apt -y install squid<\/code><\/pre>\n<p>Once the installation is completed, we need to start and enable the Squid Proxy service.<\/p>\n<h3 id=\"step-3-start-and-enable-the-squid-server\"><strong>Step 3:<\/strong> Start and enable the Squid server<\/h3>\n<p>To start and enable the service, use the following command.<\/p>\n<pre><code class=\"language-bash\">sudo systemctl start squid\nsudo systemctl enable squid<\/code><\/pre>\n<p>Once we start the service, we need to check its status.<\/p>\n<h3 id=\"step-4-check-the-status-of-the-squid-server\"><strong>Step 4:<\/strong> Check the status of the squid server<\/h3>\n<p>To check the status of the Squid proxy, use the following command.<\/p>\n<pre><code class=\"language-bash\">sudo systemctl status squid<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-145.png\" class=\"kg-image\" alt=\"the status of the squid proxy server\" loading=\"lazy\" width=\"2000\" height=\"1025\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-145.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-145.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/08\/image-145.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/08\/image-145.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The output ensures that the Squid Proxy is running without any issues, so we can configure the settings.<\/p>\n<h2 id=\"configure-proxy-server\">Configure Proxy Server<\/h2>\n<p>All the configurations for the squid server are present in <code>\/etc\/squid\/squid.conf<\/code> file.<\/p>\n<p>Before modifying the <code>squid.conf<\/code>, take the backup of the configuration file using the following commands<\/p>\n<pre><code>sudo cp \/etc\/squid\/squid.conf \/etc\/squid\/squid.conf.backup \nsudo chmod a-w \/etc\/squid\/squid.conf.backup<\/code><\/pre>\n<p>But the recommended method is to create a custom configuration file for the custom settings.<\/p>\n<h3 id=\"step-1-create-a-custom-configuration-file\">Step 1: Create a Custom Configuration File<\/h3>\n<p>To create a custom config file, Squid provides a directory <code>\/etc\/squid\/conf.d<\/code>.<\/p>\n<p>We need to create a file with the <code>.conf<\/code> extension in this directory.<\/p>\n<pre><code>sudo touch \/etc\/squid\/conf.d\/custom.conf<\/code><\/pre>\n<p>Change the ownership of the directory as <code>proxy<\/code> and set the required permissions.<\/p>\n<pre><code>sudo chown proxy:proxy \/etc\/squid\/conf.d\n\nsudo chmod 755 \/etc\/squid\/conf.d<\/code><\/pre>\n<p>Now, we can add the required configurations inside the file.<\/p>\n<h3 id=\"step-2-configure-proxy-sources-to-access-the-internet\">Step 2: Configure Proxy Sources to Access the Internet<\/h3>\n<p>To modify the configuration, open the configuration file.<\/p>\n<pre><code>sudo vim \/etc\/squid\/conf.d\/custom.conf<\/code><\/pre>\n<p>First, you need to configure the sources from which the Squid proxy should accept connections.<\/p>\n<p>For example, you might need to access this proxy server only from your home network or from specific CIDR ranges.<\/p>\n<p>You can add a source IP range with an ACL using the following format. Here, I am giving my private CIDR range as the source.<\/p>\n<pre><code class=\"language-bash\">acl localnet src 172.31.0.0\/16\nhttp_access allow localnet<\/code><\/pre>\n<p>Once you have added the configuration, save and exit the file.<\/p>\n<p>Restart the proxy server after making the ACL changes.<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart squid<\/code><\/pre>\n<blockquote><p>Note: After adding or changing any settings, restart the Squid proxy service to apply the changes.<\/p><\/blockquote>\n<h3 id=\"step-2-test-proxy-server-connectivity\">Step 2: Test Proxy Server Connectivity<\/h3>\n<p>Now, we can test how we can access a website over the proxy.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\">If you are installing Squid Proxy on cloud VMs, such as EC2, ensure that you have enabled port <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">3128<\/code> for incoming traffic.<\/p>\n<p>If you want to change the default port, you can edit the <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">squid.conf<\/code> file and modify the HTTP port entry <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">http_port 3128<\/code><\/div>\n<\/div>\n<p>To test, use the following command.<\/p>\n<pre><code class=\"language-bash\">curl -x http:\/\/&lt;squid-proxy-server-IP&gt;:3128 -I http:\/\/google.com<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-179.png\" class=\"kg-image\" alt=\"The output of accessing a website through the squid proxy\" loading=\"lazy\" width=\"2000\" height=\"1074\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-179.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-179.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/08\/image-179.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/08\/image-179.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the next section, we can configure the authentication.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\">Now, we have added only the private network, so if you try with the public IP, you will face <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">HTTP\/1.1 403 Forbidden<\/code>.<\/div>\n<\/div>\n<p>In the next section, we can configure the Squid proxy authentication.<\/p>\n<h2 id=\"configure-proxy-authentication\">Configure Proxy Authentication<\/h2>\n<p>Along with access ACL&#8217;s, you can add basic authentication to your proxy server for extra security. <\/p>\n<p>Follow the steps given below for setting up a basic auth for the squid proxy server.<\/p>\n<h3 id=\"step-1-install-httpd-tools\">Step 1<strong>:<\/strong> Install httpd-tools<\/h3>\n<p>We need to install the <code>htpasswd<\/code> utility to setup a basic authentication for Squid proxy.<\/p>\n<pre><code class=\"language-bash\">sudo apt install apache2-utils -y\n<\/code><\/pre>\n<h3 id=\"step-2-create-a-passwd-file-and-make-squid-as-the-file-owner\">Step 2<strong>:<\/strong> Create a passwd file and make squid as the file owner<\/h3>\n<p>The password file will stored the encrypted user credentials, such as username and password.<\/p>\n<p>Also, setting up the ownership as the user <code>proxy<\/code>.<\/p>\n<pre><code class=\"language-bash\">sudo touch \/etc\/squid\/passwd &amp;&amp; sudo chown proxy \/etc\/squid\/passwd<\/code><\/pre>\n<h3 id=\"step-3-add-pxuser-to-the-password-file-using-htpasswd-utility\">Step 3<strong>:<\/strong> Add <code>pxuser<\/code> to the password file using <code>htpasswd<\/code> utility. <\/h3>\n<p>Now, we need to create a username and password so that it will be used for all connections through this proxy.<\/p>\n<pre><code class=\"language-bash\"> sudo htpasswd \/etc\/squid\/passwd pxuser<\/code><\/pre>\n<p>It will prompt for a custom password. Enter a strong password you need. <\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-180.png\" class=\"kg-image\" alt=\"adding password for the squid proxy authentication\" loading=\"lazy\" width=\"1078\" height=\"450\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-180.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-180.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-180.png 1078w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now, we need to add this authentication details on the Squid configuration file.<\/p>\n<h3 id=\"step-4-add-the-authentication-settings-on-the-config-file\">Step 4<strong>:<\/strong> Add the Authentication Settings on the Config File<\/h3>\n<p>Open the configuration file.<\/p>\n<pre><code class=\"language-bash\">sudo vi \/etc\/squid\/conf.d\/custom.conf<\/code><\/pre>\n<p>Add the following to the config file and save it.<\/p>\n<pre><code class=\"language-bash\">acl localnet src 172.31.0.0\/16\n\n# Authentication parameters\n\nauth_param basic program \/usr\/lib\/squid\/basic_ncsa_auth \/etc\/squid\/passwd\nauth_param basic children 5\nauth_param basic realm Squid Basic Authentication\nauth_param basic credentialsttl 2 hours\n\n# Define ACLs\n\nacl auth_users proxy_auth REQUIRED\n\n# Allow authenticated users (for non-blocked sites)\n\nhttp_access allow auth_users\n\nhttp_access allow localnet\n\n# Deny all others\n\nhttp_access deny all\n<\/code><\/pre>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\">In Squid, the configuration rules will be applied in order. So if you want to allow something, add it before the deny all rule.<\/div>\n<\/div>\n<p>Use the following command to see whether the syntax is correct.<\/p>\n<pre><code class=\"language-bash\">sudo squid -k parse<\/code><\/pre>\n<p>Now, restart the Squid service.<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart squid<\/code><\/pre>\n<h3 id=\"step-5-test-squid-proxy-authentication\">Step 5<strong>:<\/strong> Test Squid Proxy Authentication<\/h3>\n<p>Now, we can test the connection with the authentication.<\/p>\n<pre><code>curl -x http:\/\/&lt;squid-proxy-server-IP&gt;:3128 --proxy-user pxuser:admin -I http:\/\/google.com<\/code><\/pre>\n<p>We can see the same output of the above.<\/p>\n<p>But if you are trying to access without the authentication credentials, you will see the following error.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-181.png\" class=\"kg-image\" alt=\"suqiid proxy authentication error output\" loading=\"lazy\" width=\"2000\" height=\"1352\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-181.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-181.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/08\/image-181.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-181.png 2242w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>This how we set the basic authentication on the Squid proxy. In the next section, we will configure to block websites.<\/p>\n<h2 id=\"blocking-websites-using-squid-proxy\">Blocking Websites using Squid Proxy<\/h2>\n<p>Another great use of the proxy server is restricting the website access. Follow the steps below for creating a block list.<\/p>\n<h3 id=\"step-1-adding-websites-on-the-block-list\">Step 1: Adding Websites on the Block List<\/h3>\n<p>Open a <code>.acl<\/code> file in the <code>\/etc\/squid<\/code> directory to add the websites we want to block access.<\/p>\n<pre><code class=\"language-bash\">sudo vi \/etc\/squid\/proxy-block-list.acl<\/code><\/pre>\n<p>Now, we can add the list of websites.<\/p>\n<pre><code class=\"language-bash\">facebook.com\ntwitter.com\ninstagram.com<\/code><\/pre>\n<p>Once our blocklist is ready, we need to add this on the Squid config so Squid knows which website access should block.<\/p>\n<h3 id=\"step-2-adding-acl-list-in-config-file\">Step 2: Adding ACL List in Config File<\/h3>\n<p>Open the custom Squid config and add the following configuration at the very beginning of the file.<\/p>\n<pre><code>acl bad_urls dstdomain \"\/etc\/squid\/proxy-block-list.acl\"\nhttp_access deny bad_urls<\/code><\/pre>\n<p>So your final config looks like the following <\/p>\n<pre><code>acl bad_urls dstdomain \"\/etc\/squid\/proxy-block-list.acl\"\nhttp_access deny bad_urls\n\nacl localnet src 172.31.0.0\/16\n\n# Authentication parameters\n\nauth_param basic program \/usr\/lib\/squid\/basic_ncsa_auth \/etc\/squid\/passwd\nauth_param basic children 5\nauth_param basic realm Squid Basic Authentication\nauth_param basic credentialsttl 2 hours\n\n# Define ACLs\n\nacl auth_users proxy_auth REQUIRED\n\n# Allow authenticated users (for non-blocked sites)\n\nhttp_access allow auth_users\n\nhttp_access allow localnet\n\n# Deny all others\n\nhttp_access deny all<\/code><\/pre>\n<p>Now, you should restart the Squid service.<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart squid<\/code><\/pre>\n<p>Now, we can try to access one of the blocked site through the Squid proxy.<\/p>\n<h3 id=\"step-3-test-squid-proxy-blocked-websites\">Step 3: Test Squid Proxy Blocked Websites<\/h3>\n<p>Now, if you try to access the websites that are in the block list, you will get&nbsp;a&nbsp;<code>403 error<\/code>&nbsp;as&nbsp;shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-197.png\" class=\"kg-image\" alt=\"the error message of the squid proxy blocked websites\" loading=\"lazy\" width=\"1294\" height=\"390\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-197.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-197.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-197.png 1294w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the next section, we can configure the cache configurations on the Squid Proxy.<\/p>\n<h2 id=\"cache-performance-tuning-and-logs-on-squid-proxy\">Cache, Performance Tuning and Logs on Squid Proxy<\/h2>\n<p>The caching feature in Squid proxy stores frequently accessed web content locally.<\/p>\n<p>When we access the same web content again, Squid will initially check the local cache, and if it is valid, it will show us the page from the local cache.<\/p>\n<p>This caching can reduce server load and latency.<\/p>\n<h3 id=\"step-1-add-the-cache-configuration\">Step 1:&nbsp;Add the Cache Configuration<\/h3>\n<p>Open the Squid configuration file.<\/p>\n<pre><code class=\"language-bash\">sudo vi \/etc\/squid\/conf.d\/custom.conf<\/code><\/pre>\n<p>Add the following cache configurations on the custom config file.<\/p>\n<pre><code class=\"language-bash\"># Allow caching of all allowed content\ncache allow all\n\n# Memory and disk settings\ncache_mem 512 MB\nmaximum_object_size_in_memory 512 KB\nmaximum_object_size 1024 MB\ncache_dir ufs \/var\/spool\/squid 10000 16 256\n\n# Memory and disk cache replacement policies\nmemory_replacement_policy heap GDSF\ncache_replacement_policy heap LFUDA\n\n# Static content - cache aggressively\nrefresh_pattern -i \\.(gif|png|jpg|jpeg|ico|webp)$  10080 90% 43200 override-expire ignore-reload\nrefresh_pattern -i \\.(css|js)$                     1440  90% 10080 override-expire\nrefresh_pattern -i \\.(html|htm)$                   1440  50% 10080\n\n# Specific domains\nrefresh_pattern ^http:\/\/.*\\.google\\.com\/            1440  80% 10080\n\n# Protocol patterns\nrefresh_pattern ^ftp:                               1440  20% 10080\nrefresh_pattern ^https:\/\/                           1440  70% 10080\nrefresh_pattern ^http:\/\/                            1440  70% 10080\n\n# Default catch-all (must be last)\nrefresh_pattern .                                   0     20% 4320<\/code><\/pre>\n<p>The above configuration, stores the images, CSS, JS and some HTML on in memory to speed up the browsing.<\/p>\n<p>Also, will keep some other useful files in memory and on the disk.<\/p>\n<p>Next section, we can configure the performance settings.<\/p>\n<h3 id=\"step-2-performance-tuning\">Step 2: Performance Tuning<\/h3>\n<p> For the performance tuning, you can use the following parameters<\/p>\n<pre><code class=\"language-bash\">workers 1\nclient_lifetime 1 day\n\n# Connection management \n\nclient_persistent_connections on\nserver_persistent_connections on\nhalf_closed_clients off\n\n# More conservative timeout settings\n\nconnect_timeout 60 seconds\nrequest_timeout 3 minutes\npersistent_request_timeout 1 minute\nread_timeout 3 minutes\nwrite_timeout 3 minutes\n\n# Add connection limits\n\nclient_db off\nmaximum_single_addr_tries 3<\/code><\/pre>\n<p>The above configuration defines the number of workers for traffic and open connection limits as well as timeouts.<\/p>\n<p>Next, we can configure for Squid proxy logs.<\/p>\n<h3 id=\"step-3-log-configuration\">Step 3: Log Configuration<\/h3>\n<p>For the log configuration, use the following parameters.<\/p>\n<pre><code class=\"language-sh\">access_log \/var\/log\/squid\/access.log combined\ncache_log \/var\/log\/squid\/cache.log\nlogfile_rotate 10\n\n# Enable cache status in logs\nlog_mime_hdrs off\nstrip_query_terms off<\/code><\/pre>\n<p>The above configuration will logs all the client requests, cache logs and log rotation settings.<\/p>\n<p>Once you add all the configurations, the config file looks like the following.<\/p>\n<pre><code># === BLOCKED URLS ===\nacl bad_urls dstdomain \"\/etc\/squid\/proxy-block-list.acl\"\nhttp_access deny bad_urls\n\n# === INTERNAL NETWORK ===\nacl localnet src 172.31.0.0\/16\n\n# === AUTHENTICATION SETTINGS ===\nauth_param basic program \/usr\/lib\/squid\/basic_ncsa_auth \/etc\/squid\/passwd\nauth_param basic children 5\nauth_param basic realm Squid Basic Authentication\nauth_param basic credentialsttl 2 hours\n\n# === AUTHENTICATED USERS ===\nacl auth_users proxy_auth REQUIRED\n\n# === CACHE BEHAVIOR ===\n# Allow caching of all allowed content\ncache allow all\n\n# Memory and disk settings\ncache_mem 512 MB\nmaximum_object_size_in_memory 512 KB\nmaximum_object_size 1024 MB\ncache_dir ufs \/var\/spool\/squid 10000 16 256\n\n# Cache replacement policies\nmemory_replacement_policy heap GDSF\ncache_replacement_policy heap LFUDA\n\n# === REFRESH PATTERNS ===\n# Static content - cache aggressively\nrefresh_pattern -i \\.(gif|png|jpg|jpeg|ico|webp)$  10080 90% 43200 override-expire ignore-reload\nrefresh_pattern -i \\.(css|js)$                     1440  90% 10080 override-expire\nrefresh_pattern -i \\.(html|htm)$                   1440  50% 10080\n\n# Specific domains\nrefresh_pattern ^http:\/\/.*\\.google\\.com\/            1440  80% 10080\n\n# Protocol patterns\nrefresh_pattern ^ftp:                               1440  20% 10080\nrefresh_pattern ^https:\/\/                           1440  70% 10080\nrefresh_pattern ^http:\/\/                            1440  70% 10080\n\n# Default catch-all (must be last)\nrefresh_pattern .                                   0     20% 4320\n\n# === PERFORMANCE TUNING ===\n# Use single worker for stability\nworkers 1\nclient_lifetime 1 day\n\n# Connection management\nclient_persistent_connections on\nserver_persistent_connections on\nhalf_closed_clients off\n\n# Conservative timeout settings\nconnect_timeout 60 seconds\nrequest_timeout 3 minutes\npersistent_request_timeout 1 minute\nread_timeout 3 minutes\nwrite_timeout 3 minutes\n\n# Connection limits\nclient_db off\nmaximum_single_addr_tries 3\n\n# === LOGGING ===\naccess_log \/var\/log\/squid\/access.log combined\ncache_log \/var\/log\/squid\/cache.log\nlogfile_rotate 10\n\n# Log settings\nlog_mime_hdrs off\nstrip_query_terms off\n\n# === ACCESS CONTROL ===\n# Allow authenticated users (not blocked by bad_urls)\nhttp_access allow auth_users\n\n# Allow local network\nhttp_access allow localnet\n\n# Deny all others\nhttp_access deny all\n<\/code><\/pre>\n<p>Now, we can check our configurations are correct using the following command.<\/p>\n<pre><code class=\"language-sh\">sudo squid -k parse<\/code><\/pre>\n<p>After ensuring the configurations, we need to initialize to create the cache directories.<\/p>\n<h3 id=\"step-4-initialize-cache-directories\">Step 4: Initialize Cache Directories<\/h3>\n<p>First, stop the Squid proxy service.<\/p>\n<pre><code class=\"language-sh\">sudo systemctl stop squid<\/code><\/pre>\n<p>Follow the command to create cache directories.<\/p>\n<pre><code class=\"language-sh\">sudo squid -z<\/code><\/pre>\n<h3 id=\"step-5-start-the-squid-server-and-check-the-status\">Step 5<strong>: <\/strong>Start the Squid server and check the status<\/h3>\n<p>Once the cache directories are created, we need to again start the service and check the status.<\/p>\n<pre><code class=\"language-sh\">sudo systemctl start squid\nsudo systemctl status squid<\/code><\/pre>\n<p>Now, our configurations are ready so we can test the cache.<\/p>\n<h3 id=\"step-6-test-squid-proxy-cache\">Step 6: Test squid proxy cache <\/h3>\n<p>Check the cache directory to ensure whether it is storing the cache or not<\/p>\n<pre><code class=\"language-sh\">ls -la \/var\/spool\/squid<\/code><\/pre>\n<p>You can see the following output of the Cache.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-201.png\" class=\"kg-image\" alt=\"The output of the cache directories of the squid proxy\" loading=\"lazy\" width=\"1438\" height=\"1470\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-201.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-201.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-201.png 1438w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>To test the caching, we need to access any of the non blocked website.<\/p>\n<pre><code>curl -x http:\/\/&lt;squid-proxy-server-IP&gt;:3128 --proxy-user pxuser:admin -I http:\/\/google.com<\/code><\/pre>\n<p>When you access a website for the first time, Squid will save the cache of the website. Next time, you try to access, Squid load the website from the cache so the response time will be reduced.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-198.png\" class=\"kg-image\" alt=\"the website access through the squid to identity the cache store.\" loading=\"lazy\" width=\"719\" height=\"795\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-198.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-198.png 719w\"><\/figure>\n<p>This we can even identify from the access log as well<\/p>\n<pre><code>sudo tail \/var\/log\/squid\/access.log<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-199.png\" class=\"kg-image\" alt=\"The log output of the squid access to identity the cache\" loading=\"lazy\" width=\"1834\" height=\"311\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-199.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-199.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/08\/image-199.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-199.png 1834w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<ul>\n<li><code>TCP_MISS:HIER_DIRECT<\/code> means that this URL has been requested for the first time.<\/li>\n<li><code>TCP_MEM_HTI:HIER_NONE<\/code> means that the request is served from the memory cache.<\/li>\n<\/ul>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\">If you are using the encrypted websites (HTTPS), caching won&#8217;t be happen.<\/div>\n<\/div>\n<p>Let&#8217;s check the performance difference before and after the cache.<\/p>\n<pre><code>time curl -x http:\/\/&lt;squid-proxy-server-IP&gt;:3128 --proxy-user pxuser:admin -I http:\/\/httpbin.org\/image\/jpeg -o \/dev\/null<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-200.png\" class=\"kg-image\" alt=\"squid proxy performance improvement because of cache\" loading=\"lazy\" width=\"1141\" height=\"797\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/image-200.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/image-200.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/image-200.png 1141w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>The output clearly shows that in the second time it took very less time then the first time and is because of the cache.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The blog primarily covers the setup of the Squid proxy in a Ubuntu server also the configuration.<\/p>\n<p>The features of the Squid proxy are to restrict outgoing traffic, and the caching feature helps to reduce the latency of the web content.<\/p>\n<p>You can customize the configuration more, so go through and configure as per your requirements.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/setup-and-configure-proxy-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Setup and Configures Proxy Server &#8211; Squid Proxy \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/setup-and-configure-proxy-server\/<\/p>\n","protected":false},"author":1,"featured_media":505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/505"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}