teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

不要部位の消去

2019/01/01 09:29

投稿

bunks
bunks

スコア30

title CHANGED
File without changes
body CHANGED
@@ -1,11 +1,4 @@
1
- nginxでのエラーで,
2
- 処理時間が長すぎる
3
- →504 timeout
4
- その他
5
- →502 error
6
- という認識で相違ないでしょうか?
7
-
8
- また,現在djangoで開発している中で502が出る時があり,それは処理するファイルが大きく,実行時間が長い時です。
1
+ 現在djangoで開発している中で502が出る時があり,それは処理するファイルが大きく,実行時間が長い時です。
9
2
  エラーログは以下の通りで,
10
3
  ```errorLog
11
4
  upstream prematurely closed connection while reading response header from upstream, client

1

gunicornのtimeoutと仮定し,行なった対策を追記。

2019/01/01 09:29

投稿

bunks
bunks

スコア30

title CHANGED
File without changes
body CHANGED
@@ -6,8 +6,93 @@
6
6
  という認識で相違ないでしょうか?
7
7
 
8
8
  また,現在djangoで開発している中で502が出る時があり,それは処理するファイルが大きく,実行時間が長い時です。
9
+ エラーログは以下の通りで,
10
+ ```errorLog
9
- Debug=Trueなのでdjangoのエラーではないと思っています。timeoutも3600sにしているので実行時間の問題でもないのかと考えています。
11
+ upstream prematurely closed connection while reading response header from upstream, client
12
+ ```
13
+ [こちらQiita記事](https://qiita.com/yutackall/items/e1d8bd8ebe8a992578e5)を参考にしたところ,gunicorn側のtimeoutなのではないかと思っています。(アプリ側はdebug=trueですがエラーは出ないです)
10
14
 
15
+ そのため,gunicorn.confとnginx.confを以下のように設定しましたが,gunicorn.confの設定でtimeout 3600; を追加するとエラーが出て,またそれ抜きの設定では502になります。
16
+
11
- どのようにすれば502を解決,または原因を発見きるしょうか?
17
+ どのようにすれば長い処理もkillされないtimeoutの設定にきますか?
18
+
19
+ ```gunicornConf
20
+ server {
12
- もしくは502
21
+ listen 80;
13
- (ググってもいまいち要領を得ません…)
22
+ server_name IPアドレス;
23
+ keepalive_timeout 3600;
24
+ timeout 3600; <<この行を追加するとエラーになります
25
+ location /static {
26
+ alias /var/www/static;
27
+ }
28
+
29
+ location / {
30
+ proxy_pass http://127.0.0.1:8000;
31
+ proxy_set_header Host $http_host;
32
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
33
+ }
34
+ }
35
+
36
+ ```
37
+
38
+ ```nginxConf
39
+ user nginx;
40
+ worker_processes auto;
41
+ error_log /var/log/nginx/error.log;
42
+ pid /run/nginx.pid;
43
+
44
+ # Load dynamic modules. See /usr/share/nginx/README.dynamic.
45
+ include /usr/share/nginx/modules/*.conf;
46
+
47
+ events {
48
+ worker_connections 1024;
49
+ }
50
+
51
+ http {
52
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
53
+ '$status $body_bytes_sent "$http_referer" '
54
+ '"$http_user_agent" "$http_x_forwarded_for" $request_time';
55
+
56
+ access_log /var/log/nginx/access.log main;
57
+
58
+ sendfile on;
59
+ tcp_nopush on;
60
+ tcp_nodelay on;
61
+ keepalive_timeout 3600;
62
+ proxy_connect_timeout 3600;
63
+ proxy_send_timeout 3600;
64
+ proxy_read_timeout 3600;
65
+ send_timeout 3600;
66
+ types_hash_max_size 2048;
67
+
68
+ include /etc/nginx/mime.types;
69
+ default_type application/octet-stream;
70
+
71
+ # Load modular configuration files from the /etc/nginx/conf.d directory.
72
+ # See http://nginx.org/en/docs/ngx_core_module.html#include
73
+ # for more information.
74
+ include /etc/nginx/conf.d/*.conf;
75
+
76
+ server {
77
+ listen 80 default_server;
78
+ listen [::]:80 default_server;
79
+ server_name _;
80
+ root /usr/share/nginx/html;
81
+
82
+ # Load configuration files for the default server block.
83
+ include /etc/nginx/default.d/*.conf;
84
+
85
+ location / {
86
+ }
87
+
88
+ error_page 404 /404.html;
89
+ location = /40x.html {
90
+ }
91
+
92
+ error_page 500 502 503 504 /50x.html;
93
+ location = /50x.html {
94
+ }
95
+ }
96
+ }
97
+
98
+ ```