logo
January 11, 2023

[TIL] Setup tinyproxy on Centos Linux

TIL how to build a proxy on Linux

One of the best ways to be secure while browsing the Internet is by using proxy servers. The proxy server is an important thing to know about nowadays.

What's a proxy server?

A proxy, in the English definition, is the "authority or power to act for another." A proxy server, in the computing context, is a server that acts on behalf of another server, or a user's machine.

By using a proxy to browse the Internet all of the user's Internet traffic appears to come from the proxy server instead of their machine. To set up a free high-speed proxy server all you need is a free tier AWS account.

Create your own proxy server

We will use TinyProxy to setup our server as the Proxy. Tinyproxy: https://tinyproxy.github.io/

Tinyproxy is a light-weight HTTP/HTTPS proxy daemon for POSIX operating systems. Designed from the ground up to be fast and yet small, it is an ideal solution for use cases such as embedded deployments where a full featured HTTP proxy is required, but the system resources for a larger proxy are unavailable.

We can install TinyProxy via yum command like this article Install Tinyproxy on Centos 7 . However, the TinyProxy version is 1.8.5, it is quite old. I want to use the authentication function BasicAuth so will install from the source code.

Get latest TinyProxy version

Get latest TinyProxy version from Releases page. I use the latest version 1.11.0

c
wget https://github.com/tinyproxy/tinyproxy/releases/download/1.11.0/tinyproxy-1.11.0.tar.bz2
tar -jxvf tinyproxy-1.11.0.tar.bz2
cd tinyproxy-1.11.0/
Install all dependencies

It requires some Linux packages for compile the TinyProxy from source code.

c
sudo yum update -y \
&& sudo yum install make g++ gcc autogen automake autoconf asciidoc cmake git vim -y \
&& sudo yum groupinstall 'Development Tools' -y
Build TinyProxy

In TinyProxy directory we build the binary files

c
cd tinyproxy-1.11.0/
./autogen.sh
./configure
make

Install the binary. The binary file will be installed to /usr/local/bin/tinyproxy so we need sudo

c
sudo make install

Check version

c
/usr/local/bin/tinyproxy -v
Update TinyProxy configuration

The quickest way to get started is using a minimal config file like the below:

Update the configuration file /etc/tinyproxy/tinyproxy.conf

c
sudo vim /etc/tinyproxy/tinyproxy.conf
c
User root
Group root
Port 8888
Timeout 600
DefaultErrorFile "/usr/share/tinyproxy/default.html"
Logfile "/var/log/tinyproxy.log"
LogLevel Info
PidFile "/var/run/tinyproxy.pid"
MaxRequestsPerChild 0
BasicAuth your_user your_password

Please check the document here for more detail configuration.

Create service for TinyProxy

We create a system service to keep TinyProxy running more stable.

Create the file named by /etc/systemd/system/tinyproxy.service

sudo vim /etc/systemd/system/tinyproxy.service

c
[Unit]
Description=TinyProxy Service
Requires=network.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/tinyproxy.pid
ExecStart=/usr/local/bin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
Run TinyProxy service

Enable tinyproxy service from OS start

c
sudo systemctl enable tinyproxy

Start the service

c
sudo service tinyproxy restart

Check the service status

c
sudo service tinyproxy status

The output should be like

c
$ sudo service tinyproxy status
Redirecting to /bin/systemctl status tinyproxy.service
● tinyproxy.service - TinyProxy Service
Loaded: loaded (/etc/systemd/system/tinyproxy.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2023-01-10 14:52:30 UTC; 2s ago
Process: 20361 ExecStart=/usr/local/bin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf (code=exited, status=0/SUCCESS)
Main PID: 20363 (tinyproxy)
CGroup: /system.slice/tinyproxy.service
└─20363 /usr/local/bin/tinyproxy -c /etc/tinyproxy/tinyproxy.conf
Jan 10 14:52:30 systemd[1]: Starting TinyProxy Service...
Test your own proxy

From your machine test the proxy by checking your machine IP

c
# from proxy server

Tada 🍻 Happy Proxy 🍻

Thank your for reading!

References
  • https://gist.github.com/kooroshh/2084ed52e81bcf6d60c5b0aa37524ed0
  • https://dev.to/viralsangani/be-anonymous-create-your-own-proxy-server-with-aws-ec2-2k63
  • Other articles
    More articles ➜