HTTP Proxy 安装备忘

Intro

因为一些原因需要使用 HTTP Proxy,用 GPT 3.5 生成了一下安装过程,完整走下来可以很顺利地安装和配置完成。感觉还不错,记录一下。

Install Steps

user:
how to open a http proxy on a linux server with password?
please provide client connect command as well.


assistant:
To open an HTTP proxy with a password on a Linux server, you can use the Squid proxy server. Here’s how you can set it up:

  1. Install Squid on your Linux server. The package name might vary depending on your Linux distribution. For example, on Ubuntu, you can use the following command:

    sudo apt-get install squid
  2. Once Squid is installed, open the configuration file using a text editor. On Ubuntu, the configuration file is located at /etc/squid/squid.conf.

  3. Find the section that starts with # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS. Uncomment the lines below it and modify the configuration as follows:

    auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
    acl authenticated proxy_auth REQUIRED
    http_access allow authenticated
  4. Save the configuration file and create a password file. Run the following command to create the password file:

    sudo htpasswd -c /etc/squid/passwd username

    Replace username with the desired username for authentication. You will be prompted to enter and confirm the password for the user.

  5. Restart the Squid service to apply the changes:

    sudo systemctl restart squid

Now, the HTTP proxy with password authentication is set up on your Linux server.

To connect to the proxy from a client, you can use the curl command with the --proxy option. Here’s an example command:

curl --proxy http://username:password@proxy-server-ip:proxy-port http://example.com

Replace username and password with the credentials you set up on the server. Replace proxy-server-ip with the IP address of your Linux server, and proxy-port with the port number configured for Squid (default is 3128). Finally, replace http://example.com with the URL you want to access through the proxy.

Note: Make sure to replace http:// with https:// if you are accessing an HTTPS URL.


user:
htpasswd not found


assistant:
If the htpasswd command is not found on your Linux server, it might be because the apache2-utils package, which provides the htpasswd command, is not installed.

To install apache2-utils on Ubuntu or Debian-based systems, you can use the following command:

sudo apt-get install apache2-utils

If you are using a different Linux distribution, the package name might be different. You can search for the equivalent package using the package manager of your distribution.

Once apache2-utils is installed, you should be able to use the htpasswd command to create the password file for Squid.


user:
how to change port to squid


assistant:
To change the port for the Squid proxy server, you need to modify the Squid configuration file. Here’s how you can do it:

  1. Open the Squid configuration file using a text editor. On Ubuntu, the configuration file is located at /etc/squid/squid.conf.

  2. Search for the line that starts with http_port. By default, it is set to http_port 3128.

  3. Change the port number to the desired value. For example, if you want to change it to port 8080, modify the line to:

    http_port 8080
  4. Save the configuration file.

  5. Restart the Squid service to apply the changes:

    sudo systemctl restart squid

Now, Squid will be listening on the new port that you specified.

Note: After changing the port, make sure to update any firewall or network configurations to allow traffic on the new port if necessary.


CC BY-NC-SA 4.0 本作品使用基于以下许可授权:Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注