How to Set up Your Own Web Proxy on Ubuntu 22.04/20.04 VPS

This tutorial shows you how to set up your own web proxy on Ubuntu 22.04/20.04. A web proxy is a website where a user enters a specific URL to unblock website. There are a multitude of web proxy scripts that can be used to set up your own web proxy. Glype and PHP-Proxy will be used in this tutorial.

  •  Glype is a very popular web proxy script.
  •  PHP-Proxy is a good alternative.

You can choose one of them. In my test, PHP-Proxy is faster and works better with popular websites like Facebook, Twitter and YouTube, because it’s being actively updated. We will see how to set them up with Apache/Nginx and enable HTTPS with Let’s Encrypt.

set up your own web proxy

Normally I use Shadowsocks proxy and OpenConnect VPN to bypass Internet censorship, but there’s possibility that these two tools would be blocked in my country. Web proxy is a good backup method as it doesn’t have any characteristics of SOCKS proxy and VPN. In the eyes of Internet firewall, it’s just normal HTTPS traffic. There are tens of thousands of free web proxies online. The downside is that once those public web proxies become well-known, they can be easily blocked. Setting up your own private web proxy has the advantage that only you know its existence.

Prerequisites

To follow this tutorial, you will need a VPS (Virtual Private Server) that can access blocked websites freely (Outside of your country or Internet filtering system). I recommend Kamatera VPS, which features:

  • 30 days free trial.
  • Starts at $4/month (1GB RAM)
  • High-performance KVM-based VPS
  • 9 data centers around the world, including the United States, Canada, UK, Germany, The Netherlands, Hong Kong, and Isreal.

Follow the tutorial linked below to create your Linux VPS server at Kamatera.

Once you have a VPS running Ubuntu 22.04/20.04, follow the instructions below.

You also need a domain name, so you will be able to add HTTPS encryption to protect your web traffic. I recommend buying domain names from NameCheap because the price is low and they give whois privacy protection free for life.

Step 1: Install Web Server and PHP

SSH into your Ubuntu 22.04/20.04 VPS.

If you like to use Nginx as web server, then nstall Nginx and PHP8 by executing the following command.

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php -y

sudo apt update

sudo apt install nginx php8.0-fpm php8.0-curl php8.0-mbstring php8.0-xml php8.0-zip

If you like to use Apache as web server, run

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php -y

sudo apt update

sudo apt install apache2 php8.0 libapache2-mod-php8.0 php8.0-curl php8.0-mbstring php8.0-xml php8.0-zip

Step 2: Download Glype or PHP-Proxy

Glype

Download Glype by running the following command.

wget https://www.php-proxy.com/download/glype-1.4.15.zip

Extract it to /var/www/proxy/ directory.

sudo apt install unzip

sudo mkdir -p /var/www/proxy/

sudo unzip glype-1.4.15.zip -d /var/www/proxy/

Set www-data (web server user) as the the owner.

sudo chown www-data:www-data /var/www/proxy/ -R

PHP-Proxy

We can use Composer to download PHP-Proxy. Install Composer from Ubuntu 22.04/20.04 repository.

sudo apt install composer

Then download PHP-Proxy to /var/www/proxy/ directory.

sudo mkdir -p /var/www/proxy/ /var/www/.composer/

sudo chown www-data:www-data /var/www/proxy/  /var/www/.composer/ -R

sudo -u www-data composer create-project athlon1600/php-proxy-app:dev-master /var/www/proxy/

If you are asked “Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]?” Choose Yes.

Step 3: Configure Web Server

In this step, we need to create a Nginx server block or Apache virtual host for our web proxy.

Create Nginx Server Block

Install Nginx web server.

sudo apt install nginx

Create a server block under /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/conf.d/web-proxy.conf

Copy and paste the following lines into the file. Replace proxy.example.com with your real domain name. Don’t forget to set A record in your DNS manager.

server {
        listen 80;
        server_name proxy.example.com;

        root /var/www/proxy/;
        index index.php;

        location / {
          try_files $uri $uri/ /index.php;
        }

         location ~ \.php$ {
                fastcgi_pass unix:/run/php/php8.0-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                include snippets/fastcgi-php.conf;
        }
}

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Create Apache Virtual Host

Install Apache web server.

sudo apt install apache2

Create Apache virtual host in /etc/apache2/sites-avaialable/ directory.

sudo nano /etc/apache2/sites-available/web-proxy.conf

Copy and paste the following lines into the file. Replace proxy.example.com with your real domain name. Don’t forget to set A record in your DNS manager.

<VirtualHost *:80>        
        ServerName proxy.example.com

        DocumentRoot /var/www/proxy

        ErrorLog ${APACHE_LOG_DIR}/proxy.error.log
        CustomLog ${APACHE_LOG_DIR}/proxy.access.log combined
</VirtualHost>

Save and close the file. Then enable this virtual host.

sudo a2ensite web-proxy.conf

Reload Apache for the changes to take effect.

sudo systemctl reload apache2

The Web Interface

Now visit proxy.example.com in your web browser. If you use Glype, then you will be redirected to admin control panel (proxy.example.com/admin.php).

glype web proxy

If you use PHP-Proxy, you can see a working web proxy waiting for you to enter a URL.

php-proxy

Now let’s enable HTTPS with Let’s Encrypt.

Step 4: Enable HTTPS with Let’s Encrypt for Your Web Proxy

We can install Let’s Encrypt client (certbot) by executing the following command.

sudo apt install certbot

Nginx users also need to install the Certbot Nginx plugin.

sudo apt install python-certbot-nginx

Enable HTTPS with the Nginx plugin.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d proxy.example.com --email your-email-address

Apache users need to install the Certbot Apache plugin.

sudo apt install python-certbot-apache

Enable HTTPS with the Apache plugin.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp -d proxy.example.com --email your-email-address

Once the certificate is successfully installed, refresh your proxy in your web browser to use HTTPS.

If you encounter errors when trying to obtain TLS certificate, please check out the following article to troubleshoot.

(Optional) Putting Your Web Proxy Behind CDN

There are at least three ways an Internet censor can block a website:

  • Block the IP address of the website.
  • Hijack the DNS response to give the end user a wrong IP address.
  • Block the TLS connection by looking at the Server Name Indication (SNI)

If you are worried about your web proxy being blocked by Internet censors, you can put your web proxy behind a CDN (Content Delivery Network) like Cloudflare. This way, your server IP address are hidden and if the Internet censor decide to block the Cloudflare IP address, there will be collateral damage as there are many other websites that are also using the same IP address. This will make the Internet censor think twice before doing so.

  • To prevent DNS poison, the end user should be using DNS over TLS or DNS over HTTPS.
  • To prevent leaking the SNI information, the website should be using encrypted SNI.

Troubleshooting Web Server Error

Conclusion

That’s it! I hope this tutorial helped you create your own web proxy on Ubuntu 22.04/20.04. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks.

Rate this tutorial
[Total: 24 Average: 4]

31 Responses to “How to Set up Your Own Web Proxy on Ubuntu 22.04/20.04 VPS

  • MrAdminus
    3 weeks ago

    Thank you so much for this great tutorial, upreaciate it very much!

  • Ferdinand Setiawan
    3 weeks ago

    I have install my own privateGlype proxy site and it works when I using it from the url form.
    My question is,
    Instead of submitting to the url form using POST method, Can I connect to the proxy using GET method from my php code?
    Something usual like : http://glypeproxy.site/index.php?e=url_to_visit
    Thanks!

  • Motion John
    3 weeks ago

    How do I set A record in DNS manager for Android 7?

    • Xiao Guo-An (Admin)
      3 weeks ago

      You need to have your own domain name and set A record in the web-based DNS manager of your domain registrar.

    • Xiao Guo-An (Admin)
      1 week ago

      Your VPS may have a hostname at your hosting provider’s control panel, but it’s usually not public accessible, unless you buy a domain name from a domain registrar.

  • Al Coholic
    3 weeks ago

    I have a problem.
    Do I need nginx and apachy or just one of them?
    I tried to install curl, nging and unpacked glype but i can’t get it to work.
    I get a nginx welcome unconfigured page.
    I then adjust config file to point to domain (example.com equivalent) and restart but i then get 500 error.

    • Xiao Guo-An (Admin)
      3 weeks ago

      You need to install only one web server. I personally use Nginx. You can check your web server log to find out what’s wrong.

  • 写的很好. 不过PHP-PROXY好像不支持Html播放器….有什么方法可以调式嘛?

    • Sir i asked for help regards php script for Group Selling Site… as i mentioned you that open source script to in comment… that script was written by someone 4 years ago and now it’s not working… So, will this post’s method will help to do same work with php script tool…

  • Techie
    1 week ago

    Hi, could you please do a tutorial on setting up a DNS Server with ubuntu? Always love learning from your articles, Thank you

  • great tutorial, really enjoying browsing your website

  • Lee Ward
    5 months ago

    You are a star Linuxbabe – great work. Particularly like that you always try and offer more than one option, for example Nginx or Apache. Keep it up.

  • Rand0mnis
    5 years ago

    Is it possible to create residential proxies say up to 100ips on your own home network? This is for bulk sneaker buying purposes using a bot

  • could you have video of it ..i do all this but idont understand this ???

  • Hi what shoud i write in domain A record ?(ip of my vps or what ?!)

  • Hi, I have done everything that this guide has shown (installing nginx and glype) and it does not appear to be working.

    I have tried twice now completely reinstalling ubuntu for the second try and it gets stuck at the same point.

    Whenever i try to access the server through the url I just get the nginx default page instead of redirecting me to glype’s setup.

    Both are definitely installed and the nginx config file is definitely pointing towards where glype is installed to.

    Any help would be greatly appreciated.

  • Can this be used without a domain?
    I tried putting my VPS’ IP address and _ instead of server_name (nginx) but it didn’t work.

    • Xiao Guoan (Admin)
      4 years ago

      It can work with an IP address only, but you can’t add HTTPS encryption if you don’t use a domain name, which means your web traffic can be hijacked.

    • You could get a noip.com account and use that as a web address for your server.

  • Christopher
    4 years ago

    Another excellent tutorial.
    Is there a way to add a username and password to prevent unauthorised access?

    • Christopher
      4 years ago

      I have found out how by using this tutorial:

      https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-apache-on-ubuntu-18-04

  • Thanks.

  • Thank you for this, BUT it does NOT work for me, i ve tried this more than 8 times, change server, try nginx/glype, nginx/php-proxy and apache/glype and apache/php-proxy, i have reinstalled vps several time, tried ubuntu 20.04 and 22.04. Nothing has worked so far.. not to mention, tried vultr and digitalocean. My domain A record propagates and point correctly, checked with nslookup and domain is fine, But its always

    PHP ERROR 500 with domain dns, and or nginx homepage, and or error as above when appended manually /admin.php

    Fatal error: Uncaught Error: Call to undefined function get_magic_quotes_gpc() in /var/www/proxy/admin.php:349 Stack trace: #0 /var/www/proxy/admin.php(306): Input::clean() #1 /var/www/proxy/admin.php(296): Input->prepare() #2 /var/www/proxy/admin.php(937): Input->__construct() #3 {main} thrown in /var/www/proxy/admin.php on line 349

    Please recheck the script and correct or point in the right direction whatever is the issue.

    Thank you for your effort.

    • Update:

      For those having this, Its related to php8 , downgrade to php7 and it should solve the problem.
      For example, run your installation for nginx (if thats your preference) with:

      sudo apt install apache2 php7.0 libapache2-mod-php7.0 php7.0-curl php7.0-mbstring php7.0-xml php7.0-zip

      What i did!

      • sorry command up there is for apache2, change apache2 to nginx

  • Kiya6955
    4 months ago

    Hi dear i get this error :
    Fatal error: Uncaught Error: Call to undefined function get_magic_quotes_gpc() in /var/www/proxy/admin.php:349 Stack trace: #0 /var/www/proxy/admin.php(306): Input::clean() #1 /var/www/proxy/admin.php(294): Input->prepare() #2 /var/www/proxy/admin.php(937): Input->__construct() #3 {main} thrown in /var/www/proxy/admin.php on line 349

    i downgraded php to 7 but still i have this error
    is there any solution?

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here