Last active
July 19, 2018 15:36
-
-
Save thewheat/a45941cbeab21931e00b7d5c16d4b63b to your computer and use it in GitHub Desktop.
Custom domain implementation with manual URL redirection for Intercom's Educate Help Center using a reverse proxy. Select appropriate configuration for your setup. Normal instructions on setting up custom domain will SSL detailed here https://developers.intercom.com/docs/set-up-your-custom-domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
############################################################################################# | |
# Manually handle URL redirections when transferring from an old custom domain to the new one | |
############################################################################################# | |
- This will allow you to manually redirect URLs if you move systems | |
- Likely not the best for performance reasons but is a workable solution | |
################ | |
# Instructions # | |
################ | |
1 )Get list of all links from old and new site. These commands will crawl through your sites and create links to all articles and save them to a text file | |
wget -nv -r old_site -o URLs_old.txt | |
wget -nv -r new_site -o URLs_new.txt | |
2) In the output text fields, manually find the correct mappings | |
3) Manually create PHP object of this format and save it in the 404.php file | |
$REDIRECT_URLS = [ | |
"/old/url/path" => "/new-url/path", | |
]; | |
4) Style this 404 page | |
*/ | |
$REDIRECT_URLS = [ | |
"/old/path/to/page" => "/new-page-to/page", | |
]; | |
$url = @$REDIRECT_URLS[$_SERVER["REQUEST_URI"]]; | |
if(!isset($url)) $url = @$REDIRECT_URLS[$_SERVER["REDIRECT_URL"]]; | |
if(isset($url)){ | |
header("Location: " . $url, TRUE, 301); | |
} | |
?> | |
<html><head> | |
<title>404 Not Found</title> | |
</head><body> | |
<h1>Not Found</h1> | |
<p>The requested URL was not found on this server.</p> | |
<hr> | |
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: set up normal server with HTTPS https://letsencrypt.org/ | |
# Step 2: set up proxy settings as shown below | |
# Step 3: set custom domain in Intercom Help Center settings | |
<IfModule mod_ssl.c> | |
<VirtualHost *:443> | |
ServerName your-help-site.custom-domain.com # specify your custom domain here | |
SSLEngine on | |
SSLProxyVerify none | |
SSLProxyEngine on | |
SSLProxyCheckPeerCN off | |
SSLProxyCheckPeerName off | |
SSLProxyCheckPeerExpire off | |
SSLCertificateFile /path/to/your/fullchain.pem | |
SSLCertificateKeyFile /path/to/your/privkey.pem | |
ProxyPreserveHost On | |
# manually handle URL rewrites or redirects - start | |
DocumentRoot /var/www/var/intercom-educate/ | |
ProxyPass /handle-educate-url-rewriting ! | |
ProxyErrorOverride On | |
ErrorDocument 404 /handle-educate-url-rewriting/404.php | |
# manually handle URL rewrites or redirects - end | |
ProxyPass / https://custom.intercom.help/ | |
ProxyPassReverse / https://custom.intercom.help/ | |
</VirtualHost> | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: set up normal server with HTTPS https://letsencrypt.org/ | |
# Step 2: set up proxy settings as shown below | |
# Step 3: set custom domain in Intercom Help Center settings | |
# handling uri redirects - section 1 - start | |
location ~ /handle-educate-url-rewriting/ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
error_page 404 = 404.php; | |
} | |
# handling uri redirects - section 1 - end | |
location / { | |
# handling uri redirects - section 2 - start | |
proxy_intercept_errors on; | |
error_page 404 = /handle-educate-url-rewriting/404.php; | |
# handling uri redirects - section 2 - end | |
# using "set" is important as IP addresses of Intercom servers | |
# changes dynamically. "set" enables nginx to follow dynamic IPs | |
set $intercom "https://custom.intercom.help:443"; | |
proxy_set_header Host $host; | |
proxy_pass $intercom; | |
} | |
# SSL setup - sample based on letsencrypt | |
listen 443 ssl; # managed by Certbot | |
ssl_certificate /etc/letsencrypt/live/your-help-site.custom-domain.com-0001/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/your-help-site.custom-domain.com-0001/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
# force https | |
if ($scheme != "https") { | |
return 301 https://$host$request_uri; | |
} # managed by Certbot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a simpler custom reverse proxy set up without URL redirection, just remove the references in the config above or just use these gists https://gist.github.com/thewheat/c20fa1fac53d06babf8d2046aece513c