分からないこと
railsで投稿系アプリを作成しました。
awsに手動でのデプロイは成功し,ドメインの取得、https化も下記の記事を参考にしできました。
【画像付きで丁寧に解説】AWS(EC2)にRailsアプリをイチから上げる方法【その3〜サーバー設定とRailsアプリの配置編〜】
自動でデプロイができるようにするため、capistranoも導入が完了し、ブラウザで確認したところ404 Not Foundとなりました。
ご教授頂けないでしょうか。何卒よろしくお願い致します。
#エラー内容
sudo nginx -t コマンドで確認した所
[ec2-user@ip- ~]$ sudo nginx -t nginx: [warn] conflicting server name "www.gakutabi.site" on 0.0.0.0:80, ignored nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
#現在の記述
/etc/nginx/conf.d/rails.conf
rails.conf
1error_log /var/www/rails/gakutabi/log/nginx.error.log; 2access_log /var/www/rails/gakutabi/log/nginx.access.log; 3 4upstream unicorn_server { 5 server unix:/var/www/rails/gakutabi/shared/tmp/sockets/unicorn.sock; 6} 7 8server { 9 listen 80; 10 client_max_body_size 4G; 11 server_name www.gakutabi.site; 12 13 keepalive_timeout 5; 14 15 # Location of our static files 16 root /var/www/rails/gakutabi/current/public; 17 18 location ~ ^/assets/ { 19 root /var/www/rails/gakutabi/public; 20 } 21 22 location / { 23 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 24 proxy_set_header Host $http_host; 25 proxy_redirect off; 26 27 if (!-f $request_filename) { 28 proxy_pass http://unicorn_server; 29 break; 30 } 31 } 32 33 error_page 500 502 503 504 /500.html; 34 location = /500.html { 35 root /var/www/rails/gakutabi/current/public; 36 } 37}
/etc/nginx/nginx.conf
nginx.conf
1user nginx; 2worker_processes auto; 3error_log /var/log/nginx/error.log; 4pid /run/nginx.pid; 5 6# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. 7include /usr/share/nginx/modules/*.conf; 8 9events { 10 worker_connections 1024; 11} 12 13http { 14 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 '$status $body_bytes_sent "$http_referer" ' 16 '"$http_user_agent" "$http_x_forwarded_for"'; 17 18 access_log /var/log/nginx/access.log main; 19 20 sendfile on; 21 tcp_nopush on; 22 tcp_nodelay on; 23 keepalive_timeout 65; 24 types_hash_max_size 4096; 25 26 include /etc/nginx/mime.types; 27 default_type application/octet-stream; 28 29 # Load modular configuration files from the /etc/nginx/conf.d directory. 30 # See http://nginx.org/en/docs/ngx_core_module.html#include 31 # for more information. 32 include /etc/nginx/conf.d/*.conf; 33 34 server { 35 listen 80 default_server; 36 listen [::]:80 default_server; 37 server_name www.gakutabi.site; #ドメイン名に変更 38 root /usr/share/nginx/html; 39 40 # Load configuration files for the default server block. 41 include /etc/nginx/default.d/*.conf; 42 43 location / { 44 } 45 46 error_page 404 /404.html; 47 location = /404.html { 48 } 49 50 error_page 500 502 503 504 /50x.html; 51 location = /50x.html { 52 } 53 } 54 55# Settings for a TLS enabled server. 56# 57# server { 58# listen 443 ssl http2; 59# listen [::]:443 ssl http2; 60# server_name www.gakutabi.site; 61# root /usr/share/nginx/html; 62# 63# ssl_certificate "/etc/pki/nginx/server.crt"; 64# ssl_certificate_key "/etc/pki/nginx/private/server.key"; 65# ssl_session_cache shared:SSL:1m; 66# ssl_session_timeout 10m; 67# ssl_ciphers PROFILE=SYSTEM; 68# ssl_prefer_server_ciphers on; 69# 70# # Load configuration files for the default server block. 71# include /etc/nginx/default.d/*.conf; 72# 73# error_page 404 /404.html; 74# location = /40x.html { 75# } 76# 77# error_page 500 502 503 504 /50x.html; 78# location = /50x.html { 79# } 80# } 81 82} 83
#試した事
重複してる可能性があると思い、確認
[ec2-user@ip-~]$ grep server_name /etc/nginx/conf.d/* /etc/nginx/conf.d/rails.conf: server_name www.gakutabi.site;
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/15 06:42
2021/10/15 08:08