close

繼上次某方程式不支援HTTPS後,這次又出了不支援轉址的情況,所以只好再請Nginx代為內部處理轉址而不是將轉址資訊返回給原程式

server {
    listen 80;
    server_name _;
    location /psn/ {
        proxy_pass http://127.0.0.1:90;

        proxy_intercept_errors on;           //開啟攔截http error的功能
        error_page 301 302 301 = @redirect;  //攔截指定要的代號並丟給@redirect處理
    }

    location / {
        return 301 https://account.sp-int.ac.playstation.net/;
    }

    location @handle_redirect {
        set $saved_redirect_location '$upstream_http_location'; //將30x返回的網址紀錄
        proxy_pass $saved_redirect_location;                    //重新再proxy_pass一次
    }
}

模擬了一個轉址的url在localhost,localhost/psn/負責處理發生轉址的部分

 

合併了一下上次HTTP轉成HTTPS的需求最終變成

server {
    listen 80;
    server_name _;
    location / {
        proxy_pass https://$host;             //將原http轉發為https

        proxy_intercept_errors on;            //開啟攔截http error
        error_page 301 302 301 = @redirect;   //針對指定的回應代號轉發給@redirect
    }

    location @redirect {
        set $saved_redirect_location '$upstream_http_location';  //將30x返回的網址紀錄
        proxy_pass $saved_redirect_location;                     //重新再發一次
    }
}

arrow
arrow
    文章標籤
    nginx http https redirect
    全站熱搜

    不來嗯 發表在 痞客邦 留言(0) 人氣()