Skip to content

Instantly share code, notes, and snippets.

@tearfulDalvik
Created July 17, 2020 15:39
Show Gist options
  • Save tearfulDalvik/2850542489e04afb746f95cd55863e81 to your computer and use it in GitHub Desktop.
Save tearfulDalvik/2850542489e04afb746f95cd55863e81 to your computer and use it in GitHub Desktop.
CQUPT Reverse Proxy Configuration
# Unusual ports are not supported.
server {
listen 80;
server_name endpoint.domain;
set $cqupt www.cqupt.edu.cn;
resolver 202.202.32.33 202.202.32.34 valid=3600s;
error_page 500 502 503 504 /500.html;
location = /500.html {
return 451;
}
location / {
add_header copyright "(C) Gufeng Shen 2020, All rights reserved";
add_header connect $cqupt;
proxy_set_header Accept-Encoding "";
proxy_set_header Host $cqupt;
proxy_pass http://$cqupt;
proxy_redirect ~^https?://cqupt.edu.cn/(.*) http://endpoint.domain/$1;
proxy_redirect ~^http://(.*).cqupt.edu.cn/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://(.*).cqupt.edu.cn/(.*) http://$1.secure.endpoint.domain/$2;
proxy_redirect ~^http://([0-9.]+)/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://([0-9.]+)/(.*) http://$1.secure.endpoint.domain/$2;
subs_filter 'https?://cqupt.edu.cn' http://endpoint.domain gir;
subs_filter 'http://(.*).cqupt.edu.cn' http://$1.endpoint.domain gir;
subs_filter 'https://(.*).cqupt.edu.cn' http://$1.secure.endpoint.domain gir;
subs_filter 'http://([0-9.]+)' http://$1.endpoint.domain gir;
subs_filter 'https://([0-9.]+)' http://$1.secure.endpoint.domain gir;
}
}
server {
listen 80;
server_name ~^(.+)\.secure\.endpoint\.domain$;
set $cqupt $1;
if ($cqupt ~ [a-zA-Z]) {
set $cqupt $cqupt.cqupt.edu.cn;
}
resolver 202.202.32.33 202.202.32.34 valid=3600s;
error_page 500 502 503 504 /500.html;
location = /500.html {
return 451;
}
location / {
add_header copyright "(C) Gufeng Shen 2020, All rights reserved";
add_header connect $cqupt;
proxy_set_header Accept-Encoding "";
proxy_set_header Host $cqupt;
proxy_pass https://$cqupt;
proxy_redirect ~^https?://cqupt.edu.cn/(.*) http://endpoint.domain/$1;
proxy_redirect ~^http://(.*).cqupt.edu.cn/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://(.*).cqupt.edu.cn/(.*) http://$1.secure.endpoint.domain/$2;
proxy_redirect ~^http://([0-9.]+)/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://([0-9.]+)/(.*) http://$1.secure.endpoint.domain/$2;
subs_filter 'https?://cqupt.edu.cn' http://endpoint.domain gir;
subs_filter 'http://(.*).cqupt.edu.cn' http://$1.endpoint.domain gir;
subs_filter 'https://(.*).cqupt.edu.cn' http://$1.secure.endpoint.domain gir;
subs_filter 'http://([0-9.]+)' http://$1.endpoint.domain gir;
subs_filter 'https://([0-9.]+)' http://$1.secure.endpoint.domain gir;
}
}
server {
listen 80;
server_name ~^(.+)\.endpoint\.domain$;
set $cqupt $1;
if ($cqupt ~ [a-zA-Z]) {
set $cqupt $cqupt.cqupt.edu.cn;
}
resolver 202.202.32.33 202.202.32.34 valid=3600s;
error_page 500 502 503 504 /500.html;
location = /500.html {
return 451;
}
location / {
add_header copyright "(C) Gufeng Shen 2020, All rights reserved";
add_header connect $cqupt;
proxy_set_header Host $cqupt;
proxy_set_header Accept-Encoding "";
proxy_pass http://$cqupt;
proxy_redirect ~^https?://cqupt.edu.cn/(.*) http://endpoint.domain/$1;
proxy_redirect ~^http://(.*).cqupt.edu.cn/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://(.*).cqupt.edu.cn/(.*) http://$1.secure.endpoint.domain/$2;
proxy_redirect ~^http://([0-9.]+)/(.*) http://$1.endpoint.domain/$2;
proxy_redirect ~^https://([0-9.]+)/(.*) http://$1.secure.endpoint.domain/$2;
subs_filter 'https?://cqupt.edu.cn' http://endpoint.domain gir;
subs_filter 'http://(.*).cqupt.edu.cn' http://$1.endpoint.domain gir;
subs_filter 'https://(.*).cqupt.edu.cn' http://$1.secure.endpoint.domain gir;
subs_filter 'http://([0-9.]+)' http://$1.endpoint.domain gir;
subs_filter 'https://([0-9.]+)' http://$1.secure.endpoint.domain gir;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment