Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirecting to prerender.mydomain.com #699

Closed
viperfx opened this issue Aug 16, 2021 · 1 comment
Closed

Redirecting to prerender.mydomain.com #699

viperfx opened this issue Aug 16, 2021 · 1 comment

Comments

@viperfx
Copy link

viperfx commented Aug 16, 2021

I am having an issue where NGINX redirect to my prerendering server rather than serving the HTML from the same domain.

This is roughly what happens, I go to a valid URL and add escaped_fragment to test the pre-rendering

https://domain.com/to-prerender?_escaped_fragment_

It gets redirected to the following URL in the browser

https://prerender.mydomain.com/https://domain.com/to-prerender?_escaped_fragment_

Any idea why this is happening?

I am using a NGINX proxy pass

@viperfx
Copy link
Author

viperfx commented Aug 16, 2021

This is how my NGINX config looks like

server {
    set $root /usr/share/nginx/html;

    resolver 8.8.8.8;
    set $prerender "prerender.mydomain.com";

    listen 80;
    server_name *.mydomain.com; # all subdomains

    location / {
        root $root;
        try_files $uri @prerender;
    }

    location @prerender{
        proxy_set_header X-Prerender-Token tMHIFXOFsxeqmbExUXo0;
        proxy_set_header Accept-Encoding "gzip";
        gunzip on;

        root $root;

        # don't let rate limiting or server errors interrupt a request
        proxy_intercept_errors on;
        error_page 429 500 502 503 504 =200 /index.html;


        set $prerender 0;

        if ($uri ~ "^(([^.]|\.html?)+)$") {
            set $prerender 0;
        }

        if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator|redditbot|Applebot|WhatsApp|flipboard|tumblr|bitlybot") {
            set $prerender 1;
        }

        # don't prerender if the prerender user agent is retrieving the page
        if ($http_user_agent ~ "Prerender") {
            set $prerender 0;
        }

        if ($args ~ "_escaped_fragment_") {
            set $prerender 1;
        }

        if ($prerender = 1) {
            rewrite .* /https://$host$request_uri? break;
            proxy_pass http://$prerender$uri;
            break;
        }

        rewrite .* /index.html break;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant