How to use squid to build a proxy server for http and https

How to use squid to build a proxy server for http and https

When we introduced nginx, we also used nginx to set up a forward proxy. However, if you want to support https, it is difficult to use nginx directly. It is much simpler to use squid, which specializes in this area. This article is used to record the steps to install and configure squid3.5 on centos7 to implement http and https.

Machine Configuration

[root@liumiaocn ~]# uname -a
Linux mail.163.com 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]# 
[root@liumiaocn ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
[root@liumiaocn ~]#

Install Squid

Installation command: yum install squid

Confirm version

Version confirmation: rpm -qa |grep squid

[root@liumiaocn ~]# rpm -qa |grep squid
squid-migration-script-3.5.20-12.el7.x86_64
squid-3.5.20-12.el7.x86_64
[root@liumiaocn ~]#

Confirm ip_forward

ip_forward needs to be set to 1, which is already set by default in centos. The details are as follows:

[root@liumiaocn ~]# sysctl -a |grep -w ip_forward
net.ipv4.ip_forward = 1
[root@liumiaocn ~]#

Modify the settings file

Before modification

[root@liumiaocn ~]# grep -n 'http_access deny all' /etc/squid/squid.conf
56:http_access deny all
[root@liumiaocn ~]#

After

[root@liumiaocn ~]# grep -n http /etc/squid/squid.conf |grep -w all
56:http_access allow all
[root@liumiaocn ~]#

Start Squid

systemctl start squid

Problem 1: libssl error

The following error is prompted when starting squid

squid: relocation error: squid: symbol SSL_set_alpn_protos, version libssl.so.10 not defined in file libssl.so.10 with link time reference

Reason: openssl is not installed

Corresponding method: yum install openssl

After installation, start squid:

[root@liumiaocn ~]# systemctl start squid
[root@liumiaocn ~]# systemctl status squid
● squid.service – Squid caching proxy
  Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
  Active: active (running) since Tue 2018-06-05 20:07:56 CST; 8s ago
 Process: 28548 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)
 Process: 28540 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
 Main PID: 28551 (squid)
  Memory: 14.3M
  CGroup: /system.slice/squid.service
      ├─28551 /usr/sbin/squid -f /etc/squid/squid.conf
      ├─28553 (squid-1) -f /etc/squid/squid.conf
      └─28557 (logfile-daemon) /var/log/squid/access.log
Jun 05 20:07:56 liumiaocn systemd[1]: Starting Squid caching proxy...
Jun 05 20:07:56 liumiaocn squid[28551]: Squid Parent: will start 1 kids
Jun 05 20:07:56 liumiaocn squid[28551]: Squid Parent: (squid-1) process 28553 started
Jun 05 20:07:56 liumiaocn systemd[1]: Started Squid caching proxy.
[root@liumiaocn ~]#

Problem 2: Unable to resolve domain name

At this time, it is found that the domain name cannot be used and only the IP address can be used to access

Reason: DNS is not configured. Add 8.8.8.8 and 8.8.4.4 to the Squid configuration file.

[root@liumiaocn ~]# grep nameserver /etc/squid/squid.conf
dns_nameservers 8.8.8.8 8.8.4.4
[root@liumiaocn ~]# 
[root@liumiaocn ~]# systemctl restart squid
[root@liumiaocn ~]#

Client access

The default port of Squid is 3128, which is not modified here. You can access it from the client using the following method:

HTTP method

export http_proxy=http://192.168.163.117:3128
curl http://www.baidu.com

HTTPS method

export https_proxy=http://192.168.163.117:3128
curl https://www.baidu.com

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to configure a CDN cache server using Squid reverse proxy in Linux
  • Building an experimental environment for a large website architecture (Squid cache server)
  • Squid3 cache server compilation and installation and high hit rate configuration example
  • How to use Squid to set up CDN server in CentOS
  • Choose a better cache server among Varnish, Squid, Apache, and Nginx
  • Sharing experience on setting up and maintaining Squid proxy server under Linux
  • How to simply set up a free Internet access channel for SSH+Squid proxy server
  • Using Squid to set up a proxy server in Windows
  • Detailed explanation of Squid configuration under Linux Squid proxy server configuration
  • How to use Squid as a proxy server

<<:  Solution to the failure of remote connection to MySQL database in Linux configuration

>>:  Vue resets data to its initial state

Recommend

Introduction to major browsers and their kernels

Trident core: IE, MaxThon, TT, The World, 360, So...

Mini Program natively implements left-slide drawer menu

Table of contents WXS Response Event Plan A Page ...

How to configure jdk environment under Linux

1. Go to the official website to download the jdk...

Example analysis of mysql shared lock and exclusive lock usage

This article uses examples to illustrate the usag...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

border-radius method to add rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

Pure CSS to achieve candle melting (water droplets) sample code

Achieve results Implementation ideas The melting ...

How to configure the same domain name for the front and back ends of nginx

This article mainly introduces the method of conf...

Navicat for MySql Visual Import CSV File

This article shares the specific code of Navicat ...

Automatically build and deploy using Docker+Jenkins

This article introduces Docker+Jenkins automatic ...

Detailed explanation of Json format

Table of contents A JSON is built on two structur...