質問編集履歴
5
Nginx設定ファイルの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,7 +130,7 @@
|
|
130
130
|
|
131
131
|
client_max_body_size 4G;
|
132
132
|
|
133
|
-
server_name {ALBのDNS名};
|
133
|
+
server_name {ALBのDNS名};
|
134
134
|
|
135
135
|
keepalive_timeout 5;
|
136
136
|
|
4
Nginxの設定ファイル修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,7 +130,7 @@
|
|
130
130
|
|
131
131
|
client_max_body_size 4G;
|
132
132
|
|
133
|
-
server_name {
|
133
|
+
server_name {ALBのDNS名}; ※ここのサーバー名をELBのDNS名に変更したところnginxが起動失敗するようになった
|
134
134
|
|
135
135
|
keepalive_timeout 5;
|
136
136
|
|
3
「確認したこと」修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,111 +18,89 @@
|
|
18
18
|
|
19
19
|
#確認したこと
|
20
20
|
|
21
|
-
|
21
|
+
nginxの構文を確認したところ、サーバー名の長さが上限を超えていました。(ALBのDNS名を設定しているため)
|
22
|
-
|
22
|
+
|
23
|
-
```
|
23
|
+
```
|
24
|
+
|
24
|
-
|
25
|
+
$ sudo nginx -t
|
26
|
+
|
27
|
+
[sudo] ryouya のパスワード:
|
28
|
+
|
29
|
+
nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
|
30
|
+
|
25
|
-
|
31
|
+
nginx: configuration file /etc/nginx/nginx.conf test failed
|
26
|
-
|
27
|
-
|
32
|
+
|
28
|
-
|
29
|
-
|
33
|
+
```
|
30
|
-
|
31
|
-
|
34
|
+
|
32
|
-
|
33
|
-
<title>CoffeeApp</title>
|
34
|
-
|
35
|
-
|
35
|
+
nginx設定ファイルに『server_names_hash_bucket_size 128;』を追記したいのですが、構文エラーになってしまいます。
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
#追記時のエラー_1
|
40
|
+
|
41
|
+
$ vi coffee_app.conf
|
36
42
|
|
37
43
|
:
|
38
44
|
|
45
|
+
server {
|
46
|
+
|
47
|
+
listen 80;
|
48
|
+
|
49
|
+
client_max_body_size 4G;
|
50
|
+
|
51
|
+
server_name {ALBのDNS名};
|
52
|
+
|
53
|
+
keepalive_timeout 5;
|
54
|
+
|
55
|
+
server_names_hash_bucket_size 128; #この一文を追記
|
56
|
+
|
39
57
|
:
|
40
58
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
■画面
|
56
|
-
|
57
|
-
![イメージ説明](6fa01848b13e461a9d97da52db5602e6.png)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
####・nginx.error.logでエラー出力
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
```
|
66
|
-
|
67
|
-
$ tail nginx.error.log
|
68
|
-
|
69
|
-
:
|
70
|
-
|
71
|
-
2020/05/25 14:30:38 [error] 11561#0: *96 open() "/usr/share/nginx/html/nginx-logo.png" failed (2: No such file or directory), client: 10.0.0.11, server: _, request: "GET /nginx-logo.png HTTP/1.1", host: "{ALBのDNS 名}", referrer: "http://{ALBのDNS 名}/"
|
72
|
-
|
73
|
-
```
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
####・nginx.access.logでは正常に動いていることを確認
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
```
|
82
|
-
|
83
|
-
$ tail nginx.access.log
|
84
|
-
|
85
|
-
10.0.0.11 - - [25/May/2020:14:29:47 +0000] "GET / HTTP/1.1" 200 3520 "-" "ELB-HealthChecker/2.0"
|
86
|
-
|
87
|
-
10.0.1.217 - - [25/May/2020:14:29:48 +0000] "GET / HTTP/1.1" 200 3520 "-" "ELB-HealthChecker/2.0"
|
88
|
-
|
89
|
-
10.0.0.11 - - [25/May/2020:14:29:57 +0000] "GET / HTTP/1.1" 200 3520 "-" "ELB-HealthChecker/2.0"
|
90
|
-
|
91
|
-
```
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
####・production.logでは正常に動いていることを確認
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
```
|
100
|
-
|
101
|
-
$ tail production.log
|
59
|
+
|
60
|
+
|
61
|
+
$ sudo nginx -t
|
62
|
+
|
63
|
+
nginx: [emerg] "server_names_hash_bucket_size" directive is not allowed here in /etc/nginx/conf.d/coffee_app.conf:15
|
64
|
+
|
65
|
+
nginx: configuration file /etc/nginx/nginx.conf test failed
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
#追記時のエラー_2
|
70
|
+
|
71
|
+
$ vi coffee_app.conf
|
102
72
|
|
103
73
|
:
|
104
74
|
|
75
|
+
http {
|
76
|
+
|
77
|
+
server_names_hash_bucket_size 128; #この一文を追記
|
78
|
+
|
79
|
+
server {
|
80
|
+
|
81
|
+
listen 80;
|
82
|
+
|
83
|
+
client_max_body_size 4G;
|
84
|
+
|
85
|
+
server_name {ALBのDNS名};
|
86
|
+
|
87
|
+
keepalive_timeout 5;
|
88
|
+
|
89
|
+
:
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
$ sudo nginx -t
|
94
|
+
|
105
|
-
|
95
|
+
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/coffee_app.conf:10
|
106
|
-
|
107
|
-
|
96
|
+
|
108
|
-
|
109
|
-
|
97
|
+
nginx: configuration file /etc/nginx/nginx.conf test failed
|
110
|
-
|
98
|
+
|
111
|
-
```
|
99
|
+
```
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
100
|
+
|
116
|
-
|
117
|
-
|
101
|
+
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
102
|
+
|
122
|
-
|
123
|
-
|
103
|
+
上記、記述方法がわかる方がいらっしゃいましたら、ご教示お願いします。
|
124
|
-
|
125
|
-
|
126
104
|
|
127
105
|
#関連ファイル
|
128
106
|
|
2
関連ファイルの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,6 +124,152 @@
|
|
124
124
|
|
125
125
|
|
126
126
|
|
127
|
+
#関連ファイル
|
128
|
+
|
129
|
+
####coffee_app.conf(nginx設定ファイル)
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
$ cat coffee_app.conf
|
134
|
+
|
135
|
+
error_log /var/www/rails/coffee_app/log/nginx.error.log;
|
136
|
+
|
137
|
+
access_log /var/www/rails/coffee_app/log/nginx.access.log;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
upstream unicorn_server {
|
142
|
+
|
143
|
+
server unix:/var/www/rails/coffee_app/tmp/sockets/.unicorn.sock fail_timeout=0;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
server {
|
150
|
+
|
151
|
+
listen 80;
|
152
|
+
|
153
|
+
client_max_body_size 4G;
|
154
|
+
|
155
|
+
server_name {EC2のElastic IP}; ※ここのサーバー名をELBのDNS名に変更したところnginxが起動失敗するようになった
|
156
|
+
|
157
|
+
keepalive_timeout 5;
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
# Location of our static files
|
162
|
+
|
163
|
+
root /var/www/rails/coffee_app/public;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
location ~ ^/assets/ {
|
168
|
+
|
169
|
+
root /var/www/rails/coffee_app/public;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
location / {
|
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
|
+
|
184
|
+
|
185
|
+
if (!-f $request_filename) {
|
186
|
+
|
187
|
+
proxy_pass http://unicorn_server;
|
188
|
+
|
189
|
+
break;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
error_page 500 502 503 504 /500.html;
|
198
|
+
|
199
|
+
location = /500.html {
|
200
|
+
|
201
|
+
root /var/www/rails/coffee_app/public;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
location = /favicon.ico {
|
206
|
+
|
207
|
+
log_not_found off;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
####unicorn.conf.rb
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
```
|
224
|
+
|
225
|
+
$ vi unicorn.conf.rb
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
stdout_path $std_log
|
230
|
+
|
231
|
+
timeout $timeout
|
232
|
+
|
233
|
+
listen $listen
|
234
|
+
|
235
|
+
pid $pid
|
236
|
+
|
237
|
+
# loading booster
|
238
|
+
|
239
|
+
preload_app true
|
240
|
+
|
241
|
+
# before starting processes
|
242
|
+
|
243
|
+
before_fork do |server, worker|
|
244
|
+
|
245
|
+
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
|
246
|
+
|
247
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
248
|
+
|
249
|
+
if old_pid != server.pid
|
250
|
+
|
251
|
+
begin
|
252
|
+
|
253
|
+
Process.kill "QUIT", File.read(old_pid).to_i
|
254
|
+
|
255
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
# after finishing processes
|
264
|
+
|
265
|
+
after_fork do |server, worker|
|
266
|
+
|
267
|
+
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
```
|
272
|
+
|
127
273
|
#環境
|
128
274
|
|
129
275
|
Rails 5.1.6
|
1
文言修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
AWS環境で`Nginx+Unicorn+Rails`を実装し、`EC2`に`ALB`を経由してアクセスしようとしているのですが、
|
10
10
|
|
11
|
-
`ALB`の`DNS 名`で
|
11
|
+
`ALB`の`DNS 名`でアクセスすると`Nginx`のデフォルトページが表示されてしまいます。
|
12
12
|
|
13
13
|
デプロイしている`Rails`のアプリケーションを開くためにはどのようにすればよろしいでしょうか。
|
14
14
|
|