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

質問編集履歴

4

コード改変

2019/05/14 15:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -64,7 +64,7 @@
64
64
  server {
65
65
  listen 80 default_server;
66
66
  listen [::]:80 default_server;
67
- server_name _;
67
+ server_name 【ここにIPアドレス】;
68
68
  root /usr/share/nginx/html;
69
69
 
70
70
  # Load configuration files for the default server block.
@@ -82,7 +82,7 @@
82
82
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
83
83
  proxy_set_header Host $http_host;
84
84
  proxy_redirect off;
85
- fastcgi_param HTTP_PROXY ";
85
+ fastcgi_param HTTP_PROXY "";
86
86
  proxy_pass http://myapp-master;
87
87
  }
88
88
 

3

状況追記

2019/05/14 15:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -128,4 +128,14 @@
128
128
 
129
129
  そして、`python manage.py runserver`
130
130
  こちらも同じくadminサイトへアクセスできます。
131
- その他のページは500です。
131
+ その他のページは500です。
132
+
133
+ ------追記3(5/14 16:30)--------
134
+ アプリケーションサーバーの起動コマンドは
135
+ ` gunicorn -c gunicorn.conf.py myapp.wsgi`
136
+ その時のDjangoのエラーログは
137
+ ` "GET / HTTP/1.1" 500 27`
138
+ gunicornのエラーログファイルにはエラーなし
139
+ `[INFO] Starting gunicorn 19.9.0`が羅列。
140
+ nginxについてもエラーログファイルを確認。
141
+ 同じくエラーなし(正確には、記述されていたが日付が昨日で、追記2の作業をしたのが今日だったためなしと判断)

2

状況追記

2019/05/14 07:49

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -19,14 +19,7 @@
19
19
 
20
20
  そこでどこをいじればいいのか分からないので質問しました。
21
21
 
22
- 関係あるかはわかりませんが、
23
- gunicorn -c gunicorn.conf.py myapp.wsgi
24
22
 
25
- `Error: Already running on PID 18637 (or pid file '/var/run/myapp.pid' is stale)
26
- `
27
- となります。(曖昧ですが、先ほどまでこのエラーは出なくて、同じく500だった気がします)
28
-
29
-
30
23
  加えて、このようにエラーが出た時は「どこを確認すればよい」というものはありますでしょうか?
31
24
  先日から質問を多くしてしまっているので、自分でどうにかできればと思うのですが・・・。
32
25
 
@@ -122,4 +115,17 @@
122
115
  loglevel = 'info'
123
116
  proc_name = 'myapp'
124
117
 
125
- ```
118
+ ```
119
+
120
+ ------追記2(5/14 12:00)--------
121
+ その後、自身で調査しながら、試行錯誤しています。
122
+ Django と nginx を独立させた動作確認がわからなかったので、一つずつ確認しながらもう一度設定を見てみました。
123
+ nginxとgunicornはactiveになっていて、
124
+ ` gunicorn -c gunicorn.conf.py myapp.wsgi`
125
+ からIPアドレスへアクセスすると、同じく500。
126
+ ただ、IPアドレス/admin へアクセスするとDjangoのadminサイトへアクセスできます。
127
+ ログインを行い、想定通りにオブジェクトの追加も行えました。
128
+
129
+ そして、`python manage.py runserver`
130
+ こちらも同じくadminサイトへアクセスできます。
131
+ その他のページは500です。

1

コードの追記

2019/05/14 03:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -28,4 +28,98 @@
28
28
 
29
29
 
30
30
  加えて、このようにエラーが出た時は「どこを確認すればよい」というものはありますでしょうか?
31
- 先日から質問を多くしてしまっているので、自分でどうにかできればと思うのですが・・・。
31
+ 先日から質問を多くしてしまっているので、自分でどうにかできればと思うのですが・・・。
32
+
33
+
34
+
35
+ -----追記-------
36
+ settings/prod.py
37
+ ```
38
+ from .common import *
39
+
40
+ # SECURITY WARNING: don't run with debug turned on in production!
41
+ DEBUG = False
42
+
43
+ ALLOWED_HOSTS = ['*', ]
44
+
45
+ INSTALLED_APPS += (
46
+ 'gunicorn',
47
+ )
48
+
49
+ # Database
50
+ # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
51
+
52
+ DATABASES = {
53
+ 'default': {
54
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
55
+ 'NAME': 'myapp',
56
+ 'USER': 'myapp',
57
+ 'PASSWORD': 'myapp',
58
+ 'HOST': 'localhost',
59
+ 'POST': '',
60
+ }
61
+ }
62
+ ```
63
+ nginx.conf
64
+
65
+ ```
66
+ include /etc/nginx/conf.d/*.conf;
67
+ upstream myapp-master {
68
+ server unix:/var/run/myapp.sock fail_timeout=0;
69
+ }
70
+
71
+ server {
72
+ listen 80 default_server;
73
+ listen [::]:80 default_server;
74
+ server_name _;
75
+ root /usr/share/nginx/html;
76
+
77
+ # Load configuration files for the default server block.
78
+ include /etc/nginx/default.d/*.conf;
79
+
80
+ location /static {
81
+ alias /opt/django/myapp/myapp/static;
82
+ }
83
+
84
+ location / {
85
+ try_files $uri @proxy_to_app;
86
+ }
87
+
88
+ location @proxy_to_app {
89
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
90
+ proxy_set_header Host $http_host;
91
+ proxy_redirect off;
92
+ fastcgi_param HTTP_PROXY “";
93
+ proxy_pass http://myapp-master;
94
+ }
95
+
96
+ error_page 404 /404.html;
97
+ location = /40x.html {
98
+ }
99
+
100
+ error_page 500 502 503 504 /50x.html;
101
+ location = /50x.html {
102
+ }
103
+ }
104
+ ```
105
+ gunicorn.conf.py
106
+ ```
107
+ bind = 'unix:/var/run/myapp.sock'
108
+ workers = 2
109
+ worker_connections = 1000
110
+ max_requests = 1000
111
+
112
+ debug = False
113
+ daemon = True
114
+ pidfile = '/var/run/myapp.pid'
115
+
116
+ user = 'nginx'
117
+ group = 'nginx'
118
+
119
+ errorlog = '/var/log/gunicorn/myapp-error.log'
120
+ accesslog = '/var/log/gunicorn/myapp-access.log'
121
+
122
+ loglevel = 'info'
123
+ proc_name = 'myapp'
124
+
125
+ ```