CleverCloud / documentation

Clever Cloud documentation V.2
https://developers.clever-cloud.com
17 stars 31 forks source link

Guide: prerender.io Apache integration  #361

Open juliamrch opened 1 month ago

juliamrch commented 1 month ago

Checking for existing issue

Describe the content you'd like to see

Overview

A customer has raised questions about integrating prerender.io to a Clever Cloud application. Although Prerender provides detailed documentation on stack-based integrations, the ticket showed that little was provided about Clever Cloud Apache configuration in our doc (activated modules, TLS managed by Sozu).

Why we should document it

Integrating this kind of services at Apache level might be a more generalist approach, and documenting the process would allow us to:

  1. Document more exhaustively our Apache general configuration
  2. Get a baseline for more integrations of this kind in the future
Kirbeerus commented 1 month ago

I managed to make the prerender work using HTTP.
I am not sure if it is possible using HTTPS as ssl_module is not activated in the config and you need to modify the vhost to activate SSLProxyEngine

The only change i made was to use http://service.prerender.io
You can test that prerender work using google chrome and this guide. https://docs.prerender.io/docs/how-to-test-your-site-after-you-have-successfully-validated-your-prerender-integration

Here is the code in .htaccess that worked for me, you just need to add your token.


<IfModule mod_headers.c>
    RequestHeader set X-Prerender-Token "<YOUR_TOKEN>"
    RequestHeader set X-Prerender-Version "prerender-apache@2.0.0"
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    <IfModule mod_proxy_http.c>
        RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp|redditbot|applebot|flipboard|tumblr|bitlybot|skypeuripreview|nuzzel|discordbot|google\ page\ speed|qwantify|bitrix\ link\ preview|xing-contenttabreceiver|google-inspectiontool|chrome-lighthouse|telegrambot [NC,OR]
        RewriteCond %{QUERY_STRING} _escaped_fragment_
        RewriteCond %{REQUEST_URI} ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))

        RewriteRule ^(index\.html|index\.php)?(.*) http://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}$2 [P,END]
    </IfModule>
</IfModule>