Skip to content

Instantly share code, notes, and snippets.

@thewheat
Last active July 19, 2018 15:36

Revisions

  1. thewheat revised this gist Jul 19, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,11 @@ location / {
    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 https://custom.intercom.help;
    proxy_pass $intercom;
    }


  2. thewheat revised this gist Nov 8, 2017. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,16 @@ location / {

    proxy_set_header Host $host;
    proxy_pass https://custom.intercom.help;
    }
    }


    # 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
  3. thewheat revised this gist May 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion apache.conf
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@
    ProxyPreserveHost On

    # manually handle URL rewrites or redirects - start
    DocumentRoot /var/www/thewheatfield.org/intercom/
    DocumentRoot /var/www/var/intercom-educate/
    ProxyPass /handle-educate-url-rewriting !
    ProxyErrorOverride On
    ErrorDocument 404 /handle-educate-url-rewriting/404.php
  4. thewheat created this gist May 30, 2017.
    48 changes: 48 additions & 0 deletions 404.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    <?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>
    32 changes: 32 additions & 0 deletions apache.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # 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/thewheatfield.org/intercom/
    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>
    22 changes: 22 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # 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

    proxy_set_header Host $host;
    proxy_pass https://custom.intercom.help;
    }