Score:0

Nginx sending 301 when using proxy_pass

mr flag

I have a website hosted on AWS, www.example.com. I have created a blog on Wix myblog.wixsite.com/blog. Now, I want to show the contents of myblog.wixsite.com/blog on www.example.com/blog. So I used the following Nginx conf to try & achieve that.

location /blog/ {
          sub_filter 'http://myblog.wixsite.com/' 'https://$http_host/blog/';
          sub_filter 'https://myblog.wixsite.com/' 'https://$http_host/blog/';
          sub_filter 'href="/posts/' 'href="/blog/';
          sub_filter 'href="/category/' 'href="/blog/category/';
          sub_filter 'href="/authors/' 'href="/blog/authors/';
          sub_filter 'href="/recent/' 'href="/blog/recent/';

          proxy_ssl_verify off;
          proxy_set_header Host "myblog.wixsite.com";
          proxy_set_header X-Forwarded-Host "";
          proxy_set_header X-Forwarded-For "";
          proxy_set_header Accept-Encoding "";
          proxy_set_header Cookie "";

          proxy_pass http://myblog.wixsite.com/blog/;

          proxy_redirect ~^(http://[^/]+)(/.+)$ https://$http_host$2;
        }

Now, when I hit www.example.com/blog, Nginx redirects me to https://myblog.wixsite.com/blog/ instead of showing the content on www.example.com/blog itself. I also tried changing proxy_pass http://myblog.wixsite.com/blog/; to proxy_pass https://myblog.wixsite.com/blog/; but I started getting the following error.

*532 SSL_do_handshake() failed (SSL: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error) while SSL handshaking to upstream, client: <redacted>, server: www.example.com, request: "GET /blog/ HTTP/2.0", upstream: "https://myblog.wixsite.com/blog/", host: "www.example.com"

I have been at it for a couple of days with no results. Can someone suggest what might I be doing wrong?

Score:1
us flag

It is not nginx that sends the redirect, it is the website https://myblog.wixsite.com/blog/ that sends the redirect, nginx only proxies the response it gets from the site.

mr flag
Is there a way to stop that from happening?
Score:1
tz flag

Either use proxy_redirect or change

proxy_pass http://myblog.wixsite.com/blog/; to 
proxy_pass https://myblog.wixsite.com/blog/;

Notice the protocol is https instead of http. Your wix blog is served on HTTPS anyway.

mr flag
I tried doing this as well but got stuck at an SSL Handshake error. I have updated the question with more details.
mforsetti avatar
tz flag
Try setting [`proxy_ssl_server_name`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name) to `on`.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.