私はnginxを使用しています1.14.2以下の設定でリバースプロキシとして
server {
listen xxxxxxx:80;
server_name xxxxxx;
proxy_intercept_errors on;
location /nodejs {
proxy_pass https://nodejs.org;
proxy_cache cache;
proxy_cache_valid 200 301 302 30d;
proxy_cache_valid 404 1m;
expires 30d;
proxy_ssl_server_name on;
proxy_cache_use_stale error timeout invalid_header updating;
}
}
私は502不正なゲートウェイブラウザ上:ここに画像の説明を入力してください nginx エラー ログで、次の行を見つけました:
2020/12/10 11:23:23 [error] 16462#16462: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.23.46:443/nodejs", host: "xxxxxxxx"
しかし、バックエンドにプロキシがあるため、IPアドレスを含むURLはブロックされます。アップストリームでIPアドレスの代わりにドメイン名を使用するようにnginxに強制する方法はありますか?
ありがとう。
編集: proxy_pass 設定に次の行を追加しました:
rewrite /nodejs/(.*) /dist break;
エラー ログは次のようになります。
2020/12/10 12:22:37 [error] 16541#16541: *1 connect() failed (110: Connection timed out) while connecting to upstream, client: xxxxxxx, server: xxxxxxxx, request: "GET /nodejs HTTP/1.1", upstream: "https://104.20.22.46:443/dist", host: "xxxxxxx"
答え1
このディレクティブが必要です:proxy_ssl_server_name on;
デフォルトはオフです。
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name