简体   繁体   中英

Nginx redirect to different domain keep request_uri

I wish to redirect user from my domain www.domain.com/abc/ ,
To a survey on google docs and keep my domain url in browser .
Here's what I've tried so far:

location ~ /abc/ {
        1 return 301  https://docs.google.com/forms/abcdefg?usp=sf_link;
        2 set $cleanuri $uri;
        3 return 301 docs.google.com/forms/abcdefg?usp=sf_link;
        4 proxy_set_header X-Rewrite-URL $request_uri;
        5 proxy_set_header X-Rewrite-FullURI $request_uri;
        6 proxy_set_header X-Rewrite-CleanURI $cleanuri;
}

line 1: tried to return url with line 4 proxy_set_header with request_uri .
line 2: saved uri to use with lines 3, 5, 6 to preserve original url in browser.
(hope this makes sense).
No combination worx.

You cannot use http://nginx.org/r/return here, neither 301 nor any other code, and http://nginx.org/r/proxy_set_header all by itself doesn't do anything.

You have to either use http://nginx.org/r/proxy_pass or HTML5 iframe :

  • Doing proxy_pass against docs.google.com might cause problems with too many requests coming out of a single IP address into Google Docs, which might prompt them to blacklist your IP address, and/or start giving your users captcha images to solve;it might also trigger various cross-site scripting, pfishing and hotlink protections on Google's end as well, and interfere with user authentication due to google.com cookies missing from the request; in short, this is probably not supported by Google.

  • Likewise, the HTML iframe approach is pretty much dead nowadays, due to what is known as Clickjacking, where X-Frame-Options might prevent you from doing this embedding.

In short, what you want to do is unlikely to be supported by Google Docs. Even if you do manage to make it work, it'll likely get broken rather quickly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM