前提・実現したいこと
docker-compose + nginx + Rails + mysqlという環境でアプリを作成し、起動させたいです。
発生している問題・エラーメッセージ
下記の「該当のソースコード」に記載の状態でdocker-compose upをし、localhostにアクセスしますが、nginxがrailsコンテナを見に行っている気配がありません。
localhost:3000だと問題なくrailsの「Yay! You’re on Rails!」というオープニング画面が表示されますが、localhostに接続するとWelcome to nginx!と、nginxのオープニング画面が出て来ます。
また、設定しているroutingで/api/v1/lightning/2018というのがあり、これを
__http://localhost:3000/api/v1/lightning/2018__ で実施すると問題なくdbからデータを取って来ますが、
__http://localhost/api/v1/lightning/2018__ で実施すると「404 Not Found nginx/1.15.9」というメッセージが返って来てしまいます。
その時は
2019/03/04 12:37:28 [error] 6#6: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.28.0.1, server: localhost, request: "GET /api/v1/lightning/2018 HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/lightning/2018", host: "localhost" 2019/03/04 12:37:28 [error] 6#6: *2 open() "/app/kaminari_API/kaminari_API_rails/public/500.html" failed (2: No such file or directory), client: 172.28.0.1, server: localhost, request: "GET /api/v1/lightning/2018 HTTP/1.1", upstream: "http://127.0.0.1:3000/api/v1/lightning/2018", host: "localhost"
と表示されます。
該当のソースコード
docker_compose.yml
version: '3' services: nginx: image: nginx:latest container_name: kaminari_nginx ports: - "80:80" links: - web volumes: - ./kaminari_nginx/nginx.conf:/etc/nginx/nginx.conf web: build: context: ./ dockerfile: Dockerfile_API tty: true stdin_open: true container_name: kaminari_API environment: RAILS_ENV: development volumes: - ./kaminari_API/kaminari_API_rails:/app/kaminari_API/kaminari_API_rails:rw - ./start_api.sh:/usr/local/bin/start_api.sh:ro ports: - 3000:3000 working_dir: /app/kaminari_API/kaminari_API_rails command: bash /usr/local/bin/start_api.sh db: image: mariadb:latest container_name: kaminari_db ports: - 3307:3306 environment: MYSQL_DATABASE: kaminari_API_rails_development
./kaminari_nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error_test.log debug; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access_test.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; root /app/kaminari_API/kaminari_API_rails/public; location / { proxy_pass http://app_server; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Client-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } error_page 404 /404.html; error_page 500 502 503 504 /500.html; location = /500.html { root /app/kaminari_API/kaminari_API_rails/public; } } upstream app_server { server 127.0.0.1:3000; } }
./kaminari_API/kaminari_API_rails/config/puma.rb
# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # # preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart
試していること
nginxがrailsのpumaとうまく接続できていないのではないかと思い、調べてはいるものの、迷走しています。
どんなことでもいいので、何か回答をいただきたく。。。。

回答1件
あなたの回答
tips
プレビュー