更新リクエストを処理するために nginx とノード サーバーを使用しています。大きなデータの更新を要求すると、ゲートウェイ タイムアウトが発生します。nginx エラー ログに次のエラーが表示されました:
2016/04/07 00:46:04 [エラー] 28599#0: *1 アップストリームは、アップストリームからの応答ヘッダーの読み取り中に接続を途中で閉じました。クライアント: 10.0.2.77、サーバー: gis.oneconcern.com、リクエスト: "GET /update_mbtiles/atlas19891018000415 HTTP/1.1"、アップストリーム: "http://127.0.0.1:7777/update_mbtiles/atlas19891018000415"、ホスト: "gis.oneconcern.com"
エラーをグーグルで検索し、できることはすべて試しましたが、まだエラーが発生します。
私の nginx conf には次のプロキシ設定があります:
##
# Proxy settings
##
proxy_connect_timeout 1000;
proxy_send_timeout 1000;
proxy_read_timeout 1000;
send_timeout 1000;
私のサーバーの構成はこうです
server {
listen 80;
server_name gis.oneconcern.com;
access_log /home/ubuntu/Tilelive-Server/logs/nginx_access.log;
error_log /home/ubuntu/Tilelive-Server/logs/nginx_error.log;
large_client_header_buffers 8 32k;
location / {
proxy_pass http://127.0.0.1:7777;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
location /faults {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_buffers 8 64k;
proxy_buffer_size 128k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
私は、AWS サーバーでリクエストを処理するために nodejs バックエンドを使用しています。ゲートウェイ エラーは、更新に長い時間 (約 3 ~ 4 分) がかかった場合にのみ表示されます。小さな更新ではエラーは発生しません。ご協力いただければ幸いです。
Node.jsコード:
app.get("/update_mbtiles/:earthquake", function(req, res){
var earthquake = req.params.earthquake
var command = spawn(__dirname + '/update_mbtiles.sh', [ earthquake, pg_details ]);
//var output = [];
command.stdout.on('data', function(chunk) {
// logger.info(chunk.toString());
// output.push(chunk.toString());
});
command.stderr.on('data', function(chunk) {
// logger.error(chunk.toString());
// output.push(chunk.toString());
});
command.on('close', function(code) {
if (code === 0) {
logger.info("updating mbtiles successful for " + earthquake);
tilelive_reload_and_switch_source(earthquake);
res.send("Completed updating!");
}
else {
logger.error("Error occured while updating " + earthquake);
res.status(500);
res.send("Error occured while updating " + earthquake);
}
});
});
function tilelive_reload_and_switch_source(earthquake_unique_id) {
tilelive.load('mbtiles:///'+__dirname+'/mbtiles/tipp_out_'+ earthquake_unique_id + '.mbtiles', function(err, source) {
if (err) {
logger.error(err.message);
throw err;
}
sources.set(earthquake_unique_id, source);
logger.info('Updated source! New tiles!');
});
}
ありがとう。
ベストアンサー1
プロキシのタイムアウト値を高く設定することでこの問題を解決しました。
location / {
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_pass http://localhost:3000;
}
ドキュメンテーション:nginx.org/ja/docs/http/ngx_http_proxy_module.html を参照してください。