teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

設定の詳細の追記

2021/05/10 08:46

投稿

moonlight4_6_17
moonlight4_6_17

スコア12

title CHANGED
File without changes
body CHANGED
@@ -2,8 +2,12 @@
2
2
  railsで作ったアプリを unicorn + nginx + mysql でAWSにデプロイしたい
3
3
 
4
4
  ### 起きている問題
5
- telnetコマンドで80ポートに接続できない
5
+ ~~telnetコマンドで80ポートに接続できない~~
6
+
7
+ telnetコマンドで80ポートに接続できたものの、EC2インスタンス上でcurlコマンドを使ってlocalhost/静的なページに接続しても
8
+ 「ページが見つからない」となってしまう。(詳細ログは下記)
6
9
 
10
+
7
11
  ### 原因を探った流れ
8
12
  EC2インスタンスのパブリックIPをコピペして開こうとしても開けず、以下の手順で原因を探った。
9
13
 
@@ -19,8 +23,208 @@
19
23
  ```
20
24
 
21
25
  となり、ファイアウォールの問題?と、思いセキュリティグループを確認しましたが、原因を見つけられず。。
26
+
27
+ nginxの再起動で接続できた。
28
+ ```ここに言語を入力
29
+ tanaberyouni@tanaberyouninoMacBook-Air ~ % telnet 35.72.xxx.x 80
30
+ Trying 35.72.xxx.x...
31
+ Connected to ec2-35-72-xxx-x.ap-northeast-1.compute.amazonaws.com.
32
+ Escape character is '^]'.
33
+ ^CConnection closed by foreign host.
22
34
 
35
+ ```
36
+ EC2インスタンス上からcurlコマンドでlocalhostに接続
37
+ ```ここに言語を入力
38
+ [ryoji@ip-10-0-0-225 tempo]$ curl http://localhost/
39
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
40
+ <html>
41
+ <head>
42
+ <title>Welcome to Amazon Linux 2</title>
43
+ <style rel="stylesheet" type="text/css">
44
+ html { background-color: white; font-family: "DejaVu Sans", "Liberation Sans", sans-serif; margin: 10% 20%; }
45
+ body { margin:0; padding:0; background: white; }
46
+ a { color: #007eb9; }
47
+ </style>
48
+ </head>
23
49
 
50
+ <body>
51
+
52
+ <p>Thank you for using <a href="https://aws.amazon.com/amazon-linux-2/">Amazon Linux 2</a>.<p>
53
+
54
+ <p>Now that you have it installed, find announcements and discussion in <a href="https://forums.aws.amazon.com/forum.jspa?forumID=228">the AWS Discussion Forums</a>. Also try <a href="https://aws.amazon.com/documentation/">AWS documentation</a>.</p>
55
+
56
+ </body>
57
+ </html>
58
+
59
+ ```
60
+ 同様に localhost/静的なページ に接続
61
+ ```ここに言語を入力
62
+ [ryoji@ip-10-0-0-225 tempo]$ curl http://localhost/owners/new
63
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
64
+
65
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
66
+ <head>
67
+ <title>The page is not found</title>
68
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
69
+ <style type="text/css">
70
+ /*<![CDATA[*/
71
+ body {
72
+ background-color: #fff;
73
+ color: #000;
74
+ font-size: 0.9em;
75
+ font-family: sans-serif,helvetica;
76
+ margin: 0;
77
+ padding: 0;
78
+ }
79
+ :link {
80
+ color: #c00;
81
+ }
82
+ :visited {
83
+ color: #c00;
84
+ }
85
+ a:hover {
86
+ color: #f50;
87
+ }
88
+ h1 {
89
+ text-align: center;
90
+ margin: 0;
91
+ padding: 0.6em 2em 0.4em;
92
+ background-color: #294172;
93
+ color: #fff;
94
+ font-weight: normal;
95
+ font-size: 1.75em;
96
+ border-bottom: 2px solid #000;
97
+ }
98
+ h1 strong {
99
+ font-weight: bold;
100
+ font-size: 1.5em;
101
+ }
102
+ h2 {
103
+ text-align: center;
104
+ background-color: #3C6EB4;
105
+ font-size: 1.1em;
106
+ font-weight: bold;
107
+ color: #fff;
108
+ margin: 0;
109
+ padding: 0.5em;
110
+ border-bottom: 2px solid #294172;
111
+ }
112
+ h3 {
113
+ text-align: center;
114
+ background-color: #ff0000;
115
+ padding: 0.5em;
116
+ color: #fff;
117
+ }
118
+ hr {
119
+ display: none;
120
+ }
121
+ .content {
122
+ padding: 1em 5em;
123
+ }
124
+ .alert {
125
+ border: 2px solid #000;
126
+ }
127
+
128
+ img {
129
+ border: 2px solid #fff;
130
+ padding: 2px;
131
+ margin: 2px;
132
+ }
133
+ a:hover img {
134
+ border: 2px solid #294172;
135
+ }
136
+ .logos {
137
+ margin: 1em;
138
+ text-align: center;
139
+ }
140
+ /*]]>*/
141
+ </style>
142
+ </head>
143
+
144
+ <body>
145
+ <h1><strong>nginx error!</strong></h1>
146
+
147
+ <div class="content">
148
+
149
+ <h3>The page you are looking for is not found.</h3>
150
+
151
+ <div class="alert">
152
+ <h2>Website Administrator</h2>
153
+ <div class="content">
154
+ <p>Something has triggered missing webpage on your
155
+ website. This is the default 404 error page for
156
+ <strong>nginx</strong> that is distributed with
157
+ Fedora. It is located
158
+ <tt>/usr/share/nginx/html/404.html</tt></p>
159
+
160
+ <p>You should customize this error page for your own
161
+ site or edit the <tt>error_page</tt> directive in
162
+ the <strong>nginx</strong> configuration file
163
+ <tt>/etc/nginx/nginx.conf</tt>.</p>
164
+
165
+ </div>
166
+ </div>
167
+
168
+ <div class="logos">
169
+ <a href="http://nginx.net/"><img
170
+ src="/nginx-logo.png"
171
+ alt="[ Powered by nginx ]"
172
+ width="121" height="32" /></a>
173
+
174
+ <a href="http://fedoraproject.org/"><img
175
+ src="/poweredby.png"
176
+ alt="[ Powered by Fedora ]"
177
+ width="88" height="31" /></a>
178
+ </div>
179
+ </div>
180
+ </body>
181
+ </html>
182
+
183
+ ```
184
+ となり、nginxエラー?
185
+
186
+ nginxのアクセスログをいったん見にいく
187
+ ```nginx/access.log
188
+ 127.0.0.1 - - [10/May/2021:08:27:24 +0000] "GET / HTTP/1.1" 200 732 "-" "curl/7.61.1" "-"
189
+ 127.0.0.1 - - [10/May/2021:08:27:44 +0000] "GET /owners/new HTTP/1.1" 404 3650 "-" "curl/7.61.1" "-"
190
+ ```
191
+ ### nginxの設定
192
+ ```ここに言語を入力
193
+ # log directory
194
+ error_log /var/www/rails/tempo/log/nginx.error.log;
195
+ access_log /var/www/rails/tempo/log/nginx.access.log;
196
+ # max body size
197
+ client_max_body_size 2G;
198
+ upstream app_server {
199
+ # for UNIX domain socket setups
200
+ server unix:/var/www/rails/tempo/tmp/sockets/.unicorn.sock fail_timeout=0;
201
+ }
202
+ server {
203
+ listen 80;
204
+ server_name 35.72.137.3;
205
+ # nginx so increasing this is generally safe...
206
+ keepalive_timeout 5;
207
+ # path for static files
208
+ root /var/www/rails/tempo/public;
209
+ # page cache loading
210
+ try_files $uri/index.html $uri.html $uri @app;
211
+ location @app {
212
+ # HTTP headers
213
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
214
+ proxy_set_header Host $http_host;
215
+ proxy_redirect off;
216
+ proxy_pass http://app_server;
217
+ }
218
+ # Rails error pages
219
+ error_page 500 502 503 504 /500.html;
220
+ location = /500.html {
221
+ root /var/www/rails/tempo/public;
222
+ }
223
+ }
224
+
225
+ ```
226
+
227
+
24
228
  ### EC2インスタンスのセキュリティグループ
25
229
  インバウンド
26
230
  ポート範囲 プロトコル ソース セキュリティグループ

1

エラー文の追加

2021/05/10 08:46

投稿

moonlight4_6_17
moonlight4_6_17

スコア12

title CHANGED
File without changes
body CHANGED
@@ -9,7 +9,14 @@
9
9
 
10
10
  nslookupで名前解決できているか→ 出来てる
11
11
  pingコマンドが通るか→ 通る
12
- telnetコマンドで80ポートに接続できるか →できない
12
+ telnetコマンドで80ポートに接続できるか
13
+
14
+ ```ここに言語を入力
15
+ tanaberyouni@tanaberyouninoMacBook-Air ~ % telnet 35.72.xxx.x(IPアドレス) 80
16
+ Trying 35.72.xxx.x...
17
+ telnet: connect to address 35.72.xxx.x: Connection refused
18
+ telnet: Unable to connect to remote host
19
+ ```
13
20
 
14
21
  となり、ファイアウォールの問題?と、思いセキュリティグループを確認しましたが、原因を見つけられず。。
15
22