Setup a Pirate Proxy - How to Setup Pirate bay Proxy

General Overiew

In this article, you will learn to create your own pirate bay proxy website so it will help those users where the pirate bay is banned.

First of all, we should mention the web server called NGINX. This is one of the best methods as it is a quick and easy one, doesn’t require huge resources. This method provides a lot of enhanced reverse proxy features. This server is designed to utilise minimum memory usage and provides high performance. Instead of creating new processes for every web request, NGINX uses an unsynchronized, event-driven approach where requests are processed in a single stream. It was piloted on Red Hat based and Debian based distributions; however, it works on almost all UNIX-based systems such as Ubuntu, Linux, Kali, Mac OS and so on. Your server must not have any process running on port 80 though. Default Port 80 should be empty. Moreover, it requires sufficient capacity. Avoid using a previously-compiled binary from your distributions repositories (for example, apt-get install package) as it may not have the necessary modules. Moreover, there are two PHP scripts for proxifying The Pirate Bay, which can be used on shared hosting.

NGINX

Step 1. After setting up your server, you should get to the installation of NGINX.

A: If you use a Debian based OS (for example, Ubuntu), use the following command on your terminal:

apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev gcc make git

B: If you are using a Red Hat based OS (e.g. Centos), use the below command:

yum install pcre-devel zlib-devel openssl-devel gcc make subversion

Step 2. In this step, you have to download the source code. Pay attention to the version - learn more about the version here

wget https://nginx.org/download/nginx-1.14.2.tar.gz

Step 3. Download the substitutions4nginx source with the use of subversion.

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

Step 4. Unpack the downloaded source and go to the directory.

tar xzvf nginx-1.14.2.tar.gz
cd nginx-1.14.2

Step 5. Change the path of the ngx_http_substitutions_filter_module directory to where you've downloaded it to. Skip the --with-http_ssl_module in the below command, if you aren't planning to use SSL. If you have logged in to the system as root user, the path will be: /root/ngx_http_substitutions_filter_module/

./configure --with-http_ssl_module --add-module=/path/to/ngx_http_substitutions_filter_module

Step 6. In this step, you have to compile it. By default, it'll be installed to /usr/local/nginx/ .

make
sudo make install

Step 7. Now, we have to check that nginx is working properly. We can do so by typing your server's IP address in your web browser. You should see the "Welcome to nginx!" message. This means the NGINX server has been setup successfully.

sudo /usr/local/sbin/nginx

Step 8. If its working, we'll have tostop NGINX server inorder to configure it.

sudo /usr/local/sbin/nginx -s stop

Step 9. Before proceeding further, rename the default config file to have a copy in case something goes wrong.

cd /usr/local/conf/
mv nginx.conf nginx.conf-backup

Step 10. Download this non-SSL(without https) config and open it. Have a look at it here at the website first if you're unsure.

wget https://about.piratereverse.info/proxy/nginx-ssl.conf
vi nginx.conf
OR

If you are using SSL, download the below configuration and open it. Use this command if you want to configure SSL.

wget https://about.piratereverse.info/proxy/nginx-ssl.conf
mv nginx-ssl.conf nginx.conf
vi nginx.conf

Step 11. If you aren't using SSL, then there's one thing you should consider changing which is the subs_filters, otherwise you can remove them if you are not using SSL. Then perform a find and replace. If you are using SSL, change the path of the SSL certificates as appropriate and edit the server_name such that it should be relevant.

Step 12. Now, test if the configuration is working by starting the nginx server. If you get an error like [emerg] error, something needs to be change, you have missed something in above steps. Usually the output will lead you towards the right direction. If you still can't figure out the problem, search the error in the internet, you will easily find the solution as there are a lot of resources and developers who have faced similar kind of issues.

sudo /usr/local/sbin/nginx

Step 13. That's it. Installation is complete, try it out.

PHP

This is the simplest way to setup proxy of pirate bay clone. There are two ways to get this done. It is the best solution if you don't have a dedicated server. This process also works on shared hosting. The only requirement is that your server must have PHP version of minimum 5.

SCRIPT 1:It is the recommended PHP script for creating a pirate pay clone. The process is simple. Just go to this github link and download the source souce (all files). Upload the files on the root directory of your server. That's it. Visit your domain name in the browser, you will see the pirate bay clone.

SCRIPT 2: Ther's is another script to setup pirate bay proxy. I'm sharing the code below. Please follow the procedure as exactly i am telling you. On the root directory of your server upload the below two files - .htaccess and proxy.php. That's it. These script will successfully run your proxy of pirate bay.

.htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ proxy.php?url=$1 [L,QSA]

proxy.php

< ?php class Proxy { /** * * @var curl_handle */ protected $ch; /** * URI to add before relative urls as well as default URL * @var string */ protected $prefix = 'https://thepiratebay.org/'; /** * Url to proxy.php * @var string */ protected $baseUrl; public function __construct() { $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_HEADER, true); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->ch, CURLOPT_MAXREDIRS, 10); curl_setopt($this->ch, CURLOPT_USERAGENT, 'Opera/9.23 (Windows NT 5.1; U; en)'); // TPB is returning a gzipped body, force uncompressed curl_setopt($this->ch, CURLOPT_ENCODING, 'identity'); // URL without proxy.php $this->baseUrl = substr($_SERVER['PHP_SELF'], 0, -9); } /** * Run * @param string $url * @param array $get $_GET global var * @param array $post $_POST global var * @return string Response */ public function run($url, $get, $post) { // Use default $url = $this->decodeUrl($url); // Apppend get params to request if($get) { $url .= '?'.http_build_query($get); } curl_setopt($this->ch, CURLOPT_URL, $this->prefix.'/'.$url); // set optional post params if($post) { curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post); curl_setopt($this->ch, CURLOPT_POST, true); } // See below $return = $this->curlExecFollow($this->ch); // Throw exception on error if($return === false) throw new Exception($this->error()); // Strip redirect headers $body = $return; while(strpos($body, 'HTTP') === 0) { list($header, $body) = explode("\r\n\r\n", $body, 2); } // Set response headers $this->setResponseHeaders($header); $body = preg_replace('/..thepiratebay.org/', '', $body); return $body; } protected function setResponseHeaders($header) { // Headers that should be mapped to client $mappedHeaders = array( 'Set-Cookie', 'Expires', 'Last-Modified', 'Cache-Control', 'Content-Type', 'Pragma' ); // Parse headers $headers = $this->parseHeaders($header); foreach($headers as $name => $value) { // If header isn't mapped, don't set it if(!array_search($name, $mappedHeaders)) continue; // Support for multiple values with same name if(is_array($value)) foreach($value as $part) header($name.': '.$part, false); else header($name.': '.$value); } } // Parse headers into array protected function parseHeaders($header) { $retVal = array(); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); foreach( $fields as $field ) { if( preg_match('/([^:]+): (.+)/m', $field, $match) ) { $match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); if( isset($retVal[$match[1]]) ) { $retVal[$match[1]] = array($retVal[$match[1]], $match[2]); } else { $retVal[$match[1]] = trim($match[2]); } } } return $retVal; } /** * * @param string $url * @return string */ protected function decodeUrl($url) { return str_replace(' ', '%20', $url); } /** * Get error message * @return string */ protected function error() { return curl_error($this->ch); } /** * Allow redirects under safe mode * @param curl_handle $ch * @return string */ protected function curlExecFollow($ch) { $mr = 5; if (ini_get('open_basedir') == '' && (ini_get('safe_mode') == 'Off' || ini_get('safe_mode') == '')) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($ch, CURLOPT_MAXREDIRS, $mr); } else { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); if ($mr > 0) { $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $rch = curl_copy_handle($ch); curl_setopt($rch, CURLOPT_HEADER, true); curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); curl_setopt($rch, CURLOPT_RETURNTRANSFER, true); do { if(strpos($newurl, '/') === 0) $newurl = $this->prefix.$newurl; curl_setopt($rch, CURLOPT_URL, $newurl); $header = curl_exec($rch); if (curl_errno($rch)) { $code = 0; } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/', $header, $matches); $newurl = str_replace(' ', '%20', trim(array_pop($matches))); } else { $code = 0; } } } while ($code && --$mr); curl_close($rch); if (!$mr) { if ($maxredirect === null) { trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING); } else { $maxredirect = 0; } return false; } curl_setopt($ch, CURLOPT_URL, $newurl); } } return curl_exec($ch); } } try { // Use '' al default if(isset($_GET['url'])) { $url = $_GET['url']; unset($_GET['url']); } else { $url = ''; } $proxy = new Proxy(); echo $proxy->run($url, $_GET, $_POST); } catch(Exception $e) { echo 'Error: '.$e->getMessage(); } ? >

If the above code doesn’t work, visit this github page.

Advice for Setuping a new Proxy - PirateBay

Find a reliable web host for setting up pirate bay proxy.

Find a hosting provider which doesn't care about DMCA requests. That web host should not be located in the United Kingdom or USA. Some hosting companies in Europe also implement DMCA takedowns. Therefore, do a research on the internet before choosing your web host. Search in google for keywords like VPS, Dedicated Server, Offshore, etc.

Use a CDN - Content Delivery Network

Using a CDN service like Cloudflare has a lot of benefits. CDNs improve your website speed and accelerate your website and reduce the server response time, so it prevents the load the your server. Additionally, it will also hide the actual location of web server. Another free CDN provider is Incapsula.

Remark: If you decide to use Cloudflare, then you’ll have to add proxy_set_header CF-Connecting-IP ''; to your NGINX configuration to make it work. Failing this, you may get DNS errors.

Use SSL/TCL (secure security layer)

SSL is very important these days for websites as they provides user a confidence that the site they are visiting are secure. If you use Cloudflare, it automatically delivers a SSL certificate for your domain using which you can add https in front of the domain. In case you purchase your own certificate, make sure to comply with the SSL best practices, like providing HSTS and using advanced encryptions.

Selecting the best Domain Registrar

We will suggest you to use purchase your domain from NameCheap, EasyDNS, or Hover. Avoid using GoDaddy, NameCheap, Web.co, and Register.com.

Use WHOIS privacy on your domain name

After you register a domain name, your account information such as your email, address, phone number is visible to the public domain which is known as WHOIS database. Therefore, anyone can view your details on Whois searche engine and get information about you. There are some domain registrar which don't support WHOIS privacy and may request your details to be open. In such scenarios, you should try to fill the wrong data.

Receive a free domain name

There are many ways you can get a free domain name. Even the domain name I am using is free. I have registered my domain on FREENOM. There are many more like this. There is FreeDNS which also gives you a free subdomain with a domain. But, there's one drawback in using these free domains, you cannot use CDN services like Cloudflare on it as they don't allow to change nameservers.

Monitor your website

After creating your proxy of piratebay clone, you should keep monitor your web traffic using google analytics and the performace and speed of your website on googlepagespeed insights, gtmetrix, and pingdom tools. Also, monitor your website regularly for any errors using tools like Uptime robold, Monitor.us and Montastic.