Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save beveradb/44bba10d66796a53c3c68570783f437e to your computer and use it in GitHub Desktop.
Save beveradb/44bba10d66796a53c3c68570783f437e to your computer and use it in GitHub Desktop.
Nginx reverse proxy to third party website with rewritten content and working booking process (with limitations) - demo for s8
# Set up the s8.beveradb.com subdomain by default as a reverse proxy to andrew's website with rewrite rule for links, assets etc.
location / {
proxy_ssl_server_name on;
proxy_pass https://andrewbeveridge.co.uk/;
sub_filter_types *;
sub_filter_once off;
sub_filter 'andrewbeveridge.co.uk' 's8.beveradb.com';
}
# Set up the showcase path as a reverse proxy to showcasecinemas' website, with rewrite rules for assets, and hide header/footer
location /showcase/ {
# Proxy requests starting with /showcase/ to the showcase domain, with path
proxy_ssl_server_name on;
proxy_pass https://www.showcasecinemas.co.uk/;
# Perform filters/replacements below on all file types (e.g. css/js), not just HTML
sub_filter_types *;
sub_filter_once off;
# Rewrite most assets (e.g. CSS, JS) to fetch from subdirectory
sub_filter 'href="/' 'href="/showcase/';
sub_filter "href='/" "href='/showcase/";
sub_filter 'src="/' 'src="/showcase/';
sub_filter "src='/" "src='/showcase/";
sub_filter 'url("/' 'url("/showcase/';
sub_filter "url('/" "url('/showcase/";
sub_filter "url(/" "url(/showcase/";
# Some assets try to load from this subdomain - possibly just ads or tracking though
sub_filter "https://as.showcasecinemas.co.uk" "/showcase-as";
# Inject CSS to hide the header and footer
sub_filter '</head>' '<style>.section-header, .section-footer {display: none;}</style></head>';
}
# Needed for some assets to load - possibly just ads or tracking though
location /showcase-as/ {
proxy_ssl_server_name on;
proxy_pass https://as.showcasecinemas.co.uk/;
}
# Some bit of JS code must have hard-coded the /booking URL so we have to redirect this
location /booking/ {
# Proxy requests starting with /showcase/ to the showcase domain, with path
proxy_ssl_server_name on;
proxy_pass https://www.showcasecinemas.co.uk/booking/;
# Perform filters/replacements below on all file types (e.g. css/js), not just HTML
sub_filter_types *;
sub_filter_once off;
# Rewrite most assets (e.g. CSS, JS) to fetch from subdirectory
sub_filter 'href="/' 'href="/showcase/';
sub_filter "href='/" "href='/showcase/";
sub_filter 'src="/' 'src="/showcase/';
sub_filter "src='/" "src='/showcase/";
sub_filter 'url("/' 'url("/showcase/';
sub_filter "url('/" "url('/showcase/";
sub_filter "url(/" "url(/showcase/";
# Some assets try to load from this subdomain - possibly just ads or tracking though
sub_filter "https://as.showcasecinemas.co.uk" "/showcase-as";
}
# Some of the JS code loaded hard-codes this path, this is a bit of a lazy way to get it working without wasting too much time reverse-engineering their JS code.
location /booking {
# Proxy requests starting with /showcase/ to the showcase domain, with path
proxy_ssl_server_name on;
proxy_pass https://www.showcasecinemas.co.uk/booking;
# Perform filters/replacements below on all file types (e.g. css/js), not just HTML
sub_filter_types *;
sub_filter_once off;
# Rewrite most assets (e.g. CSS, JS) to fetch from subdirectory
sub_filter 'href="/' 'href="/showcase/';
sub_filter "href='/" "href='/showcase/";
sub_filter 'src="/' 'src="/showcase/';
sub_filter "src='/" "src='/showcase/";
sub_filter 'url("/' 'url("/showcase/';
sub_filter "url('/" "url('/showcase/";
sub_filter "url(/" "url(/showcase/";
# Some assets try to load from this subdomain - possibly just ads or tracking though
sub_filter "https://as.showcasecinemas.co.uk" "/showcase-as";
}
location /umbraco/ {
# Proxy requests starting with /showcase/ to the showcase domain, with path
proxy_ssl_server_name on;
proxy_pass https://www.showcasecinemas.co.uk/umbraco/;
}
location /Umbraco/ {
# Proxy requests starting with /showcase/ to the showcase domain, with path
proxy_ssl_server_name on;
proxy_pass https://www.showcasecinemas.co.uk/Umbraco/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment