質問編集履歴
7
/etc/nginx/conf.d/rails.conf追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -296,7 +296,11 @@
|
|
296
296
|
|
297
297
|
```
|
298
298
|
|
299
|
+
```
|
300
|
+
|
299
|
-
|
301
|
+
Nginxエラーログ
|
302
|
+
|
303
|
+
|
300
304
|
|
301
305
|
2021/04/17 17:08:29 [error] 22948#0: *6 open() "/var/www/アプリケーション名/current/public/assets/application-796485acc5c1b3047846fd111ee629a32c9e3776a00951b710b65463d118fa3f.css" failed (2: No such file or directory), client: ~~~, server: Elastic IP名, request: "GET /assets/application-796485acc5c1b3047846fd111ee629a32c9e3776a00951b710b65463d118fa3f.css HTTP/1.1", host: "the-expenses.work", referrer: "http://the-expenses.work/users/sign_in"
|
302
306
|
|
@@ -304,6 +308,90 @@
|
|
304
308
|
|
305
309
|
```
|
306
310
|
|
311
|
+
```
|
312
|
+
|
313
|
+
/etc/nginx/conf.d/rails.conf
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
upstream app_server {
|
318
|
+
|
319
|
+
# Unicornと連携させるための設定
|
320
|
+
|
321
|
+
server unix:/var/www/The-Expenses-95/shared/tmp/sockets/unicorn.sock;
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
# {}で囲った部分をブロックと呼ぶ。サーバの設定ができる
|
328
|
+
|
329
|
+
server {
|
330
|
+
|
331
|
+
# このプログラムが接続を受け付けるポート番号
|
332
|
+
|
333
|
+
listen 80;
|
334
|
+
|
335
|
+
# 接続を受け付けるリクエストURL ここに書いていないURLではアクセスできない
|
336
|
+
|
337
|
+
server_name ElasticIP番号 the-expenses.work;
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
# クライアントからアップロードされてくるファイルの容量の上限を2ギガに設定。デフォルトは1メガなので大きめにしておく
|
342
|
+
|
343
|
+
client_max_body_size 2g;
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
# 接続が来た際のrootディレクトリ
|
348
|
+
|
349
|
+
root /var/www/The-Expenses-95/current/public;
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
# assetsファイル(CSSやJavaScriptのファイルなど)にアクセスが来た際に適用される設定
|
354
|
+
|
355
|
+
location ^~ /assets/ {
|
356
|
+
|
357
|
+
gzip_static on;
|
358
|
+
|
359
|
+
expires max;
|
360
|
+
|
361
|
+
add_header Cache-Control public;
|
362
|
+
|
363
|
+
root /var/www/アプリケーション名/current/public;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
try_files $uri/index.html $uri @unicorn;
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
location @unicorn {
|
374
|
+
|
375
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
376
|
+
|
377
|
+
proxy_set_header Host $http_host;
|
378
|
+
|
379
|
+
proxy_redirect off;
|
380
|
+
|
381
|
+
proxy_pass http://app_server;
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
error_page 500 502 503 504 /500.html;
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
```
|
394
|
+
|
307
395
|
|
308
396
|
|
309
397
|
|
6
Nginxエラーログ
test
CHANGED
File without changes
|
test
CHANGED
@@ -296,6 +296,14 @@
|
|
296
296
|
|
297
297
|
```
|
298
298
|
|
299
|
+
```Nginx
|
300
|
+
|
301
|
+
2021/04/17 17:08:29 [error] 22948#0: *6 open() "/var/www/アプリケーション名/current/public/assets/application-796485acc5c1b3047846fd111ee629a32c9e3776a00951b710b65463d118fa3f.css" failed (2: No such file or directory), client: ~~~, server: Elastic IP名, request: "GET /assets/application-796485acc5c1b3047846fd111ee629a32c9e3776a00951b710b65463d118fa3f.css HTTP/1.1", host: "the-expenses.work", referrer: "http://the-expenses.work/users/sign_in"
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
```
|
306
|
+
|
299
307
|
|
300
308
|
|
301
309
|
|
5
エラー画像
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,6 +22,12 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
# エラー
|
26
|
+
|
27
|
+
![イメージ説明](1ba0f4fcba3871da8c33703f558c8aed.png)
|
28
|
+
|
29
|
+
|
30
|
+
|
25
31
|
```ruby
|
26
32
|
|
27
33
|
config/deploy/production.rb
|
4
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -248,6 +248,50 @@
|
|
248
248
|
|
249
249
|
```
|
250
250
|
|
251
|
+
```ruby
|
252
|
+
|
253
|
+
capistrano.log
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
|
258
|
+
|
259
|
+
This can impact web performance.
|
260
|
+
|
261
|
+
Assets:
|
262
|
+
|
263
|
+
js/application-ea23ae402b20ce672355.js (541 KiB)
|
264
|
+
|
265
|
+
js/application-ea23ae402b20ce672355.js.map.gz (528 KiB)
|
266
|
+
|
267
|
+
js/application-ea23ae402b20ce672355.js.map.br (447 KiB)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
|
272
|
+
|
273
|
+
Entrypoints:
|
274
|
+
|
275
|
+
application (541 KiB)
|
276
|
+
|
277
|
+
js/application-ea23ae402b20ce672355.js
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
WARNING in webpack performance recommendations:
|
284
|
+
|
285
|
+
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
|
286
|
+
|
287
|
+
For more info visit https://webpack.js.org/guides/code-splitting/
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
```
|
292
|
+
|
293
|
+
|
294
|
+
|
251
295
|
|
252
296
|
|
253
297
|
# 参考記事
|
3
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -220,6 +220,34 @@
|
|
220
220
|
|
221
221
|
```
|
222
222
|
|
223
|
+
```ruby
|
224
|
+
|
225
|
+
Capfile
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
require "capistrano/setup"
|
230
|
+
|
231
|
+
require "capistrano/deploy"
|
232
|
+
|
233
|
+
require 'capistrano/rbenv'
|
234
|
+
|
235
|
+
require 'capistrano/bundler'
|
236
|
+
|
237
|
+
require 'capistrano/rails/assets'
|
238
|
+
|
239
|
+
require 'capistrano/rails/migrations'
|
240
|
+
|
241
|
+
require 'capistrano3/unicorn'
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|
250
|
+
|
223
251
|
|
224
252
|
|
225
253
|
# 参考記事
|
2
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,6 +22,206 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
```ruby
|
26
|
+
|
27
|
+
config/deploy/production.rb
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
server 'Elastic IP', user: 'ec2-user', roles: %w{app db web}
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
|
39
|
+
config/unicorn.rb
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
app_path = File.expand_path('../../../', __FILE__)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
#アプリケーションサーバの性能を決定する
|
48
|
+
|
49
|
+
worker_processes 1
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
#アプリケーションの設置されているディレクトリを指定
|
54
|
+
|
55
|
+
working_directory "#{app_path}/current"
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
#Unicornの起動に必要なファイルの設置場所を指定
|
60
|
+
|
61
|
+
pid "#{app_path}/shared/tmp/pids/unicorn.pid"
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
#ポート番号を指定
|
66
|
+
|
67
|
+
listen "#{app_path}/shared/tmp/sockets/unicorn.sock"
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
#エラーのログを記録するファイルを指定
|
72
|
+
|
73
|
+
stderr_path "#{app_path}/shared/log/unicorn.stderr.log"
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
#通常のログを記録するファイルを指定
|
78
|
+
|
79
|
+
stdout_path "#{app_path}/shared/log/unicorn.stdout.log"
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
#Railsアプリケーションの応答を待つ上限時間を設定
|
84
|
+
|
85
|
+
timeout 60
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
#以下は応用的な設定なので説明は割愛
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
preload_app true
|
94
|
+
|
95
|
+
GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
check_client_connection false
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
run_once = true
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
before_fork do |server, worker|
|
108
|
+
|
109
|
+
defined?(ActiveRecord::Base) &&
|
110
|
+
|
111
|
+
ActiveRecord::Base.connection.disconnect!
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
if run_once
|
116
|
+
|
117
|
+
run_once = false # prevent from firing again
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
124
|
+
|
125
|
+
if File.exist?(old_pid) && server.pid != old_pid
|
126
|
+
|
127
|
+
begin
|
128
|
+
|
129
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
130
|
+
|
131
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
132
|
+
|
133
|
+
rescue Errno::ENOENT, Errno::ESRCH => e
|
134
|
+
|
135
|
+
logger.error e
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
after_fork do |_server, _worker|
|
146
|
+
|
147
|
+
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
|
155
|
+
config/deploy.rb
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
lock '3.16.0'
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
set :application, 'アプリ名'
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
# どのリポジトリからアプリをpullするかを指定する
|
168
|
+
|
169
|
+
set :repo_url, 'githubリポジトリ'
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
# バージョンが変わっても共通で参照するディレクトリを指定
|
174
|
+
|
175
|
+
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
set :rbenv_type, :user
|
180
|
+
|
181
|
+
set :rbenv_ruby, '2.6.5'
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
# どの公開鍵を利用してデプロイするか
|
186
|
+
|
187
|
+
set :ssh_options, auth_methods: ['publickey'],
|
188
|
+
|
189
|
+
keys: ['#']
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
# プロセス番号を記載したファイルの場所
|
194
|
+
|
195
|
+
set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
# Unicornの設定ファイルの場所
|
200
|
+
|
201
|
+
set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" }
|
202
|
+
|
203
|
+
set :keep_releases, 5
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
# デプロイ処理が終わった後、Unicornを再起動するための記述
|
208
|
+
|
209
|
+
after 'deploy:publishing', 'deploy:restart'
|
210
|
+
|
211
|
+
namespace :deploy do
|
212
|
+
|
213
|
+
task :restart do
|
214
|
+
|
215
|
+
invoke 'unicorn:restart'
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
|
224
|
+
|
25
225
|
# 参考記事
|
26
226
|
|
27
227
|
以下の記事を参考にドメインを取得しました。
|
1
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,12 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
# インフラ構築
|
20
|
+
|
21
|
+
![イメージ説明](f041240183eb3ed8d8d8d4223c455cf6.png)
|
22
|
+
|
23
|
+
|
24
|
+
|
19
25
|
# 参考記事
|
20
26
|
|
21
27
|
以下の記事を参考にドメインを取得しました。
|