How to set up your own proxy server in minutes?
Tags: programming, tutorial, cloud, javascript
Published: 2024-01-27 04:47:47

Today, most websites track your online activities by capturing essential information such as IP addresses, cookies, and geolocation. All this information starts associating with the user, and a unique user profile is created over time. This helps the trackers to track the user’s activities over the internet, which in the end results in privacy concerns.

Unlike third-party cookies, there is no straightforward way to opt out of this kind of tracking.

1. [What is a Proxy Server?](#what-is-a-proxy-server)
   
   1.1 [Benefits of using a Proxy Server](#benefits-of-using-a-proxy-server)

2. [So, how to make our proxy server?](#so-how-to-make-our-proxy-server)
   
   2.1 [Prerequisites](#prerequisites)

   2.2 [Create an Ubuntu Server](#create-an-ubuntu-server)

   2.3 [Configuring the Server](#configuring-the-server)

   2.4 [Setting up the proxy locally](#setting-up-the-proxy-locally)

   2.5 [Testing the proxy server](#testing-the-proxy-server)
   
3. [Conclusion](#conclusion)



## What is a Proxy Server?

A proxy server is an intermediate server that acts as a gateway between the user’s device and the internet. When a user makes a request for a resource, let’s say a website, the request is first sent to the proxy server. The proxy server then forwards the request to the website’s server on behalf of the user. 

![Untitled](https://res.cloudinary.com/dtscloud/image/upload/v1700734309/Post%20Images/proxy-server-1.png)

### Benefits of using a Proxy Server

- **Privacy Protection:** Proxy servers can be used to protect the user’s privacy. They are used to hide the user’s actual IP address from the websites they visit.
- **Improved Performance:** Proxy servers can be used to cache the requests that are frequently accessed. This helps in faster response and reduces the bandwidth usage.
- **Optimal Performance:** In a server having large traffic (requests), proxy servers can be used for load balancing. Requests from the users are distributed across multiple servers to provide optimal performance and prevent the single server from being overloaded by the huge traffic.
- **Enhanced Security:** As we discussed earlier, the proxy server provides an additional layer of security by acting as the middleman between the user’s device and the internet. They can filter out the malicious content and block certain types of attacks.

Proxy servers can be operated at different OSI models, including the HTTP proxies, transport proxies (SOCKS proxies), or even the lower layers.

## So, how to make our proxy server?

### Prerequisites

- Any cloud service provider account. (DigitalOcean Recommended)
- One Ubuntu 20.04 or later server, with at least 512MB of RAM.

### Create an Ubuntu Server

In this tutorial, I will be using DigitalOcean to host my VPS.

Create an account on DigitalOcean, if you haven’t done so yet.

[Use my referral link to create an account on DigitalOcean](https://m.do.co/c/59c3a25113a5) to get $200 worth of credits for 60 days.

Now create a new project. 

In the sidebar click **New Project**:

![Create New Project](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-2.jpg)

Enter a name, for example, “**Proxy Server”**.

Choose something in the “Tell us what it’s for” box, or you can’t create the project. Then click **Create Project**.

In the next page, click “Skip for now”

![Skip for now](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-3.jpg)

The project has now been created.

Now, click on **Spin up a Droplet** to create a VPS (Virtual Private Server).

![Spin up a droplet](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-4.jpg)

This shows the interface for creating a new droplet.

Choose a region where you want your internet activity to be routed through the proxy.

![Choose a region](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-5.jpg)

To initiate the installation of Ubuntu on your Droplet, simply pick the Ubuntu option from the 'Choose an image' section.

Now, choose the droplet size. The default selection is the 'Premium Intel/AMD' CPUs, but for our current needs, we don't require that level of power. Instead, opt for the 'Regular' CPU option, which comes with a $4 per month plan. Note that in certain regions, the $4 per month plan may not be accessible, so in such cases, pick the most economical plan offered in that region.

![Choose the droplet size](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-6.jpg)

Now go down below, and set up a strong root user password.

![Create strong root password](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-7.jpg)

Finally, create the **Droplet**.

It may take some time to boot the server. Once the server starts running, copy the IPv4 address.

![Copy to ipv4 address](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-8.jpg)

Now, we have successfully configured our server setup.

### Configuring the Server

Open the terminal, and login to your Ubuntu server using `openssh`.

```bash
ssh root@YOUR_SERVER_IPV4
```

After you log into your Ubuntu server. Install `openssh-server`.

```bash
apt install openssh-server
```

Once you have finished installing, log out from the server.

```bash
exit
```

### Setting up the proxy locally

On your local machine, open the terminal and run the following command,

```bash
ssh -D 2402 -N  -C root@YOUR_SERVER_IPV4
```

Now open the Firefox browser, and open the settings. In settings, search for the “Proxy”. 

![Firefox > settings> proxy](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-9.jpg)

Now click on the “Settings”,

![Manual Proxy Configuration](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-10.jpg)

Choose, the “Manual Proxy Configuration”, and enter the details in the **SOCKS Host** input field as shown in the above image.

`localhost` | `PORT: 2402`

Now click on OK, and you have successfully configured the proxy.

### Testing the proxy server

Before connecting to the proxy server:

![Before connecting to proxy server](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-11.jpg)

After connecting to the proxy server:

![After connecting to proxy server](https://res.cloudinary.com/dtscloud/image/upload/v1700734234/Post%20Images/proxy-server-12.jpg)

### Conclusion

So, this is how we can set up a proxy server on our own, and protect our privacy, and maintain anonymity online.

I hope this article, was helpful to you. Thanks for reading!

[Follow me on X](https://twitter.com/dhairyashah_dev/)

Originally published on [my blog](https://www.dhairyashah.dev/posts/how-to-build-a-rest-api-with-hono-in-5-minutes/)

Cover Photo by <a href="https://unsplash.com/@scottrodgerson?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Scott Rodgerson</a> on <a href="https://unsplash.com/photos/a-bunch-of-blue-wires-connected-to-each-other-PSpf_XgOM5w?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>