Use Nginx to Step Up Generic Proxy Server
In my case, i want to have a generic proxy server to proxy some static asserts which had been reseted by China GFW.
Give a detail example, SwitchyOmega
is famous proxy client on Chrome, theres an option you can set for Auto Proxy
, you need provide a url so that SwitchyOmega
can auto download from it.
The good news is that theres already exist a service on github to provide a rule file called gfwlist/gfwlist, but the bad news is github some times not reachable because of the GFW
, so if you have a proxy server, you can just use it to proxy github file.
Here is my solution for that:
https://go.dist.pub/raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
You can see the origin url just follow a domain name, its simple and powerful. Also i setup a magic on schema
, it will go through to the destination server.
What does it mean?
It means the middle proxy server will request to github follow the origin request schema like below:
https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
Thats all!
server {
...
set $real_host 'localhost';
if ($request_uri ~* ^/(.+?)/(.*)$) {
set $real_host $1;
}
if ($real_host = 'localhost') { return 204; }
if ($real_host = '127.0.0.1') { return 204; }
if ($real_host ~* ^localhost\:) { return 204; }
if ($real_host ~* ^127.0.0.1\:) { return 204; }
location / {
proxy_set_header Host $real_host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass "$scheme:/$request_uri";
...
}
}