Nginx 使用 proxy_pass 時傳送 301

Nginx 使用 proxy_pass 時傳送 301

我有一個託管在 AWS 上的網站,www.example.com。我在 Wix myblog.wixsite.com/blog 上建立了一個部落格。現在,我想在以下位置顯示 myblog.wixsite.com/blog 的內容www.example.com/blog。所以我使用以下 Nginx conf 來嘗試實現這一目標。

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;
        }

現在,當我擊中www.example.com/blog, Nginx 將我重新導向到https://myblog.wixsite.com/blog/而不是顯示內容www.example.com/blog本身。我也嘗試更改 proxy_pass http://myblog.wixsite.com/blog/;為, proxy_pass https://myblog.wixsite.com/blog/; 但開始出現以下錯誤。

*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"

我已經研究了幾天了,但沒有任何結果。有人可以建議我可能做錯了什麼嗎?

答案1

要么使用proxy_redirect或改變

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

請注意協議https不是http.無論如何,您的 wix 部落格都是透過 HTTPS 提供服務的。

答案2

發送重新導向的不是 nginx,而是https://myblog.wixsite.com/blog/發送重新導向的網站,nginx 僅代理從網站獲得的回應。

相關內容