質問編集履歴

2

内容の変更

2021/07/29 14:49

投稿

yuu0000
yuu0000

スコア4

test CHANGED
@@ -1 +1 @@
1
- ECSでnginxではなくRailsアプリケーションを表示させたい
1
+ ECSデプロイしたRailsアプリケーションを表示させたい
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
 
17
-
17
+ **パブリックIPアドレス**、**DNS**、**独自ドメイン**でそれぞれアクセスしてみましたが、すべて``Welcome to nginx!``が表示されました。
18
18
 
19
19
 
20
20
 
@@ -120,6 +120,10 @@
120
120
 
121
121
 
122
122
 
123
+ ECS周りの設定などを調べてみましたが、設定などは正しく入力されていたのでDocker関係の設定に原因があると考えています。
124
+
125
+
126
+
123
127
  ### 該当のソースコード
124
128
 
125
129
 
@@ -322,6 +326,64 @@
322
326
 
323
327
 
324
328
 
329
+ ``docker-compose.yml``
330
+
331
+
332
+
333
+ ```
334
+
335
+ version: '3'
336
+
337
+ services:
338
+
339
+ db:
340
+
341
+ image: mysql:5.7
342
+
343
+ environment:
344
+
345
+ MYSQL_ROOT_PASSWORD: password
346
+
347
+ MYSQL_DATABASE: root
348
+
349
+ ports:
350
+
351
+ - "4306:3306"
352
+
353
+ volumes:
354
+
355
+ - ./mysql-confd:/etc/mysql/conf.d
356
+
357
+ web:
358
+
359
+ build: .
360
+
361
+ command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
362
+
363
+ volumes:
364
+
365
+ - .:/locat
366
+
367
+ ports:
368
+
369
+ - 3000:3000
370
+
371
+ depends_on:
372
+
373
+ - db
374
+
375
+ tty: true
376
+
377
+ stdin_open: true
378
+
379
+ volumes:
380
+
381
+ mysql-data:
382
+
383
+ ```
384
+
385
+
386
+
325
387
  ### 試したこと
326
388
 
327
389
 
@@ -404,6 +466,214 @@
404
466
 
405
467
 
406
468
 
469
+
470
+
471
+ ###### 修正したファイル
472
+
473
+
474
+
475
+ ``nginx/Dockerfile``
476
+
477
+
478
+
479
+ ```
480
+
481
+ FROM nginx:1.19.1
482
+
483
+ RUN apt-get update && \
484
+
485
+ apt-get install -y apt-utils \
486
+
487
+ locales && \
488
+
489
+ sed -i -e 's/# ja_JP.UTF-8/ja_JP.UTF-8/g' /etc/locale.gen && \
490
+
491
+ locale-gen ja_JP.UTF-8
492
+
493
+ ENV LANG ja_JP.UTF-8
494
+
495
+ ENV LC_TIME C
496
+
497
+ ADD ./nginx/nginx.conf /etc/nginx/nginx.conf
498
+
499
+ ADD ./nginx/default.conf /etc/nginx/conf.d/default.conf
500
+
501
+ ```
502
+
503
+
504
+
505
+ ``nginx/default.conf``
506
+
507
+
508
+
509
+ ```
510
+
511
+ upstream locat {
512
+
513
+ server unix:///locat/tmp/sockets/puma.sock;
514
+
515
+ }
516
+
517
+
518
+
519
+ server {
520
+
521
+ listen 80 default_server;
522
+
523
+ server_name locat-app.com;
524
+
525
+ root /locat/public;
526
+
527
+ try_files $uri/index.html $uri @locat;
528
+
529
+
530
+
531
+ proxy_connect_timeout 600;
532
+
533
+ proxy_read_timeout 600;
534
+
535
+ proxy_send_timeout 600;
536
+
537
+
538
+
539
+ client_max_body_size 100m;
540
+
541
+ error_page 404 /404.html;
542
+
543
+ error_page 505 502 503 504 /500.html;
544
+
545
+
546
+
547
+ location / {
548
+
549
+ proxy_set_header X-Real-IP $remote_addr;
550
+
551
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
552
+
553
+ proxy_set_header Host $http_host;
554
+
555
+ proxy_pass http://locat;
556
+
557
+ }
558
+
559
+ }
560
+
561
+ ```
562
+
563
+
564
+
565
+ ``puma.rb``
566
+
567
+
568
+
569
+ ```
570
+
571
+ # Puma can serve each request in a thread from an internal thread pool.
572
+
573
+ # The `threads` method setting takes two numbers: a minimum and maximum.
574
+
575
+ # Any libraries that use thread pools should be configured to match
576
+
577
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
578
+
579
+ # and maximum; this matches the default thread size of Active Record.
580
+
581
+ #
582
+
583
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
584
+
585
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
586
+
587
+ threads min_threads_count, max_threads_count
588
+
589
+
590
+
591
+ # Specifies the `worker_timeout` threshold that Puma will use to wait before
592
+
593
+ # terminating a worker in development environments.
594
+
595
+ #
596
+
597
+ worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
598
+
599
+
600
+
601
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
602
+
603
+ #
604
+
605
+ port ENV.fetch("PORT") { 3000 }
606
+
607
+
608
+
609
+ # Specifies the `environment` that Puma will run in.
610
+
611
+ #
612
+
613
+ environment ENV.fetch("RAILS_ENV") { "development" }
614
+
615
+
616
+
617
+ # Specifies the `pidfile` that Puma will use.
618
+
619
+ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
620
+
621
+
622
+
623
+ # Specifies the number of `workers` to boot in clustered mode.
624
+
625
+ # Workers are forked web server processes. If using threads and workers together
626
+
627
+ # the concurrency of the application would be max `threads` * `workers`.
628
+
629
+ # Workers do not work on JRuby or Windows (both of which do not support
630
+
631
+ # processes).
632
+
633
+ #
634
+
635
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
636
+
637
+
638
+
639
+ # Use the `preload_app!` method when specifying a `workers` number.
640
+
641
+ # This directive tells Puma to first boot the application and load code
642
+
643
+ # before forking the application. This takes advantage of Copy On Write
644
+
645
+ # process behavior so workers use less memory.
646
+
647
+ #
648
+
649
+ # preload_app!
650
+
651
+
652
+
653
+ # Allow puma to be restarted by `rails restart` command.
654
+
655
+ plugin :tmp_restart
656
+
657
+ app_root = File.expand_path('..', __dir__)
658
+
659
+ bind "unix://#{app_root}/tmp/sockets/puma.sock"
660
+
661
+
662
+
663
+ stdout_redirect "#{app_root}/log/puma.stdout.log", "#{app_root}/log/puma.stderr.log", true
664
+
665
+
666
+
667
+ ```
668
+
669
+
670
+
671
+ >
672
+
673
+ - nginxファイル、pumaの設定などに変更を加えてみましたが、変わらず``Welcome to nginx!``が表示されました。
674
+
675
+ >
676
+
407
677
  * タスクは **Railsコンテナ**(``ローカルでRails用に設定しているDockerfile``)と**nginxコンテナ**(``ローカルでnginx用に作成したDockerfile``)を独立して作成しております。
408
678
 
409
679
 

1

書式の編集

2021/07/29 14:49

投稿

yuu0000
yuu0000

スコア4

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
- https://gyazo.com/36abe339d3dec52ada91a95594988e5c
35
+ [ブラウザ画面のスクリーンショット](https://gyazo.com/36abe339d3dec52ada91a95594988e5c)
36
36
 
37
37
 
38
38