Home  >  Article  >  Operation and Maintenance  >  How to set up a proxy server (like Squid) on Linux

How to set up a proxy server (like Squid) on Linux

WBOY
WBOYOriginal
2023-07-06 11:57:063088browse

How to set up a proxy server (such as Squid) on Linux

Introduction:
A proxy server is a common network tool that can provide secure and efficient network connections and access control. In Linux systems, we can use various proxy server software to implement proxy functions, among which Squid is a very popular choice. This article will introduce how to install and configure the Squid proxy server on Linux and provide relevant code examples.

Step One: Install Squid Proxy Server
Installing Squid on a Linux system is very simple, just execute the following command:

sudo apt-get update
sudo apt-get install squid

This will automatically download and Install Squid proxy server software.

Step 2: Configure the Squid proxy server

  1. Open the Squid configuration file
    The Squid configuration file is located at /etc/squid/squid.conf , use a text editor to open it:

    sudo nano /etc/squid/squid.conf
  2. Configure Access Control List (ACL)
    In Squid’s configuration file, we need to define the Access Control List (ACL) to determine which network addresses have permission to use the proxy server. The following is a code snippet of an example ACL configuration:

    acl localnet src 192.168.0.0/16
    acl allowed_sites dstdomain .example.com

    In the above code, we define an ACL of localnet, indicating that network addresses from the 192.168.0.0/16 subnet are allowed to access the proxy server. In addition, we also defined an ACL of allowed_sites, which represents the network address that is allowed to access the .example.com domain name.

  3. Configuring Access Rules
    In Squid's configuration file, we need to define access rules to determine which requests will go through the proxy server and which requests will connect directly to the target server. The following is a code snippet for an example access rule configuration:

    http_access allow localnet
    http_access allow allowed_sites
    http_access deny all

    In the above code, we define a rule to allow access requests from the ACLs of localnet and allowed_sites proxy server, while denying all other requests.

  4. Configuring the proxy listening port
    In the Squid configuration file, we also need to specify the port that the proxy server listens on. The following is a sample configuration code snippet:

    http_port 3128

    In the above code, we configure the proxy server to listen on port 3128.

Step 3: Start and test the Squid proxy server

  1. Start the Squid service
    Execute the following command to start the Squid service:

    sudo service squid start
  2. Testing the proxy server
    Now, we can test through the configured proxy server. In the browser's proxy settings, set the proxy server's address to the IP address of the Linux host and the specified port number (for example, 3128). Then, try visiting various websites and verify that the proxy server is working properly.

Conclusion:
Through the above steps, we successfully installed and configured the Squid proxy server. Please keep in mind that in actual use, you may need to make more configuration adjustments based on your specific network environment and needs to achieve more precise and secure proxy functions.

The above is the detailed content of How to set up a proxy server (like Squid) on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn