質問編集履歴

4

コード改変

2019/05/14 15:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -130,7 +130,7 @@
130
130
 
131
131
  listen [::]:80 default_server;
132
132
 
133
- server_name _;
133
+ server_name 【ここにIPアドレス】;
134
134
 
135
135
  root /usr/share/nginx/html;
136
136
 
@@ -166,7 +166,7 @@
166
166
 
167
167
  proxy_redirect off;
168
168
 
169
- fastcgi_param HTTP_PROXY ";
169
+ fastcgi_param HTTP_PROXY "";
170
170
 
171
171
  proxy_pass http://myapp-master;
172
172
 

3

状況追記

2019/05/14 15:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -259,3 +259,23 @@
259
259
  こちらも同じくadminサイトへアクセスできます。
260
260
 
261
261
  その他のページは500です。
262
+
263
+
264
+
265
+ ------追記3(5/14 16:30)--------
266
+
267
+ アプリケーションサーバーの起動コマンドは
268
+
269
+ ` gunicorn -c gunicorn.conf.py myapp.wsgi`
270
+
271
+ その時のDjangoのエラーログは
272
+
273
+ ` "GET / HTTP/1.1" 500 27`
274
+
275
+ gunicornのエラーログファイルにはエラーなし
276
+
277
+ `[INFO] Starting gunicorn 19.9.0`が羅列。
278
+
279
+ nginxについてもエラーログファイルを確認。
280
+
281
+ 同じくエラーなし(正確には、記述されていたが日付が昨日で、追記2の作業をしたのが今日だったためなしと判断)

2

状況追記

2019/05/14 07:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -40,20 +40,6 @@
40
40
 
41
41
 
42
42
 
43
- 関係あるかはわかりませんが、
44
-
45
- gunicorn -c gunicorn.conf.py myapp.wsgi
46
-
47
-
48
-
49
- `Error: Already running on PID 18637 (or pid file '/var/run/myapp.pid' is stale)
50
-
51
- `
52
-
53
- となります。(曖昧ですが、先ほどまでこのエラーは出なくて、同じく500だった気がします)
54
-
55
-
56
-
57
43
 
58
44
 
59
45
  加えて、このようにエラーが出た時は「どこを確認すればよい」というものはありますでしょうか?
@@ -247,3 +233,29 @@
247
233
 
248
234
 
249
235
  ```
236
+
237
+
238
+
239
+ ------追記2(5/14 12:00)--------
240
+
241
+ その後、自身で調査しながら、試行錯誤しています。
242
+
243
+ Django と nginx を独立させた動作確認がわからなかったので、一つずつ確認しながらもう一度設定を見てみました。
244
+
245
+ nginxとgunicornはactiveになっていて、
246
+
247
+ ` gunicorn -c gunicorn.conf.py myapp.wsgi`
248
+
249
+ からIPアドレスへアクセスすると、同じく500。
250
+
251
+ ただ、IPアドレス/admin へアクセスするとDjangoのadminサイトへアクセスできます。
252
+
253
+ ログインを行い、想定通りにオブジェクトの追加も行えました。
254
+
255
+
256
+
257
+ そして、`python manage.py runserver`
258
+
259
+ こちらも同じくadminサイトへアクセスできます。
260
+
261
+ その他のページは500です。

1

コードの追記

2019/05/14 03:14

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -59,3 +59,191 @@
59
59
  加えて、このようにエラーが出た時は「どこを確認すればよい」というものはありますでしょうか?
60
60
 
61
61
  先日から質問を多くしてしまっているので、自分でどうにかできればと思うのですが・・・。
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+ -----追記-------
70
+
71
+ settings/prod.py
72
+
73
+ ```
74
+
75
+ from .common import *
76
+
77
+
78
+
79
+ # SECURITY WARNING: don't run with debug turned on in production!
80
+
81
+ DEBUG = False
82
+
83
+
84
+
85
+ ALLOWED_HOSTS = ['*', ]
86
+
87
+
88
+
89
+ INSTALLED_APPS += (
90
+
91
+ 'gunicorn',
92
+
93
+ )
94
+
95
+
96
+
97
+ # Database
98
+
99
+ # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
100
+
101
+
102
+
103
+ DATABASES = {
104
+
105
+ 'default': {
106
+
107
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
108
+
109
+ 'NAME': 'myapp',
110
+
111
+ 'USER': 'myapp',
112
+
113
+ 'PASSWORD': 'myapp',
114
+
115
+ 'HOST': 'localhost',
116
+
117
+ 'POST': '',
118
+
119
+ }
120
+
121
+ }
122
+
123
+ ```
124
+
125
+ nginx.conf
126
+
127
+
128
+
129
+ ```
130
+
131
+ include /etc/nginx/conf.d/*.conf;
132
+
133
+ upstream myapp-master {
134
+
135
+ server unix:/var/run/myapp.sock fail_timeout=0;
136
+
137
+ }
138
+
139
+
140
+
141
+ server {
142
+
143
+ listen 80 default_server;
144
+
145
+ listen [::]:80 default_server;
146
+
147
+ server_name _;
148
+
149
+ root /usr/share/nginx/html;
150
+
151
+
152
+
153
+ # Load configuration files for the default server block.
154
+
155
+ include /etc/nginx/default.d/*.conf;
156
+
157
+
158
+
159
+ location /static {
160
+
161
+ alias /opt/django/myapp/myapp/static;
162
+
163
+ }
164
+
165
+
166
+
167
+ location / {
168
+
169
+ try_files $uri @proxy_to_app;
170
+
171
+ }
172
+
173
+
174
+
175
+ location @proxy_to_app {
176
+
177
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
178
+
179
+ proxy_set_header Host $http_host;
180
+
181
+ proxy_redirect off;
182
+
183
+ fastcgi_param HTTP_PROXY “";
184
+
185
+ proxy_pass http://myapp-master;
186
+
187
+ }
188
+
189
+
190
+
191
+ error_page 404 /404.html;
192
+
193
+ location = /40x.html {
194
+
195
+ }
196
+
197
+
198
+
199
+ error_page 500 502 503 504 /50x.html;
200
+
201
+ location = /50x.html {
202
+
203
+ }
204
+
205
+ }
206
+
207
+ ```
208
+
209
+ gunicorn.conf.py
210
+
211
+ ```
212
+
213
+ bind = 'unix:/var/run/myapp.sock'
214
+
215
+ workers = 2
216
+
217
+ worker_connections = 1000
218
+
219
+ max_requests = 1000
220
+
221
+
222
+
223
+ debug = False
224
+
225
+ daemon = True
226
+
227
+ pidfile = '/var/run/myapp.pid'
228
+
229
+
230
+
231
+ user = 'nginx'
232
+
233
+ group = 'nginx'
234
+
235
+
236
+
237
+ errorlog = '/var/log/gunicorn/myapp-error.log'
238
+
239
+ accesslog = '/var/log/gunicorn/myapp-access.log'
240
+
241
+
242
+
243
+ loglevel = 'info'
244
+
245
+ proc_name = 'myapp'
246
+
247
+
248
+
249
+ ```