質問編集履歴

4

修正後

2020/11/09 08:22

投稿

yutaro_0529
yutaro_0529

スコア12

test CHANGED
File without changes
test CHANGED
@@ -42,8 +42,16 @@
42
42
 
43
43
  nginx: configuration file /etc/nginx/nginx.conf test failed
44
44
 
45
+ [ec2-user@ip-172-31-45-251 ~]$ sudo systemctl start nginx
46
+
47
+ [ec2-user@ip-172-31-45-251 ~]$ sudo systemctl reload nginx
48
+
45
49
  [ec2-user@ip-172-31-45-251 ~]$
46
50
 
51
+
52
+
53
+ おそらく問題なくnginxを起動することができたと思います。
54
+
47
55
  ```
48
56
 
49
57
 

3

修正後してみました。

2020/11/09 08:22

投稿

yutaro_0529
yutaro_0529

スコア12

test CHANGED
File without changes
test CHANGED
@@ -26,9 +26,31 @@
26
26
 
27
27
 
28
28
 
29
+ 修正後↓
30
+
31
+ ```EC2ターミナル
32
+
33
+ [ec2-user@ip-172-31-45-251 ~]$ nginx -t
34
+
35
+ nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
36
+
37
+ 2020/11/09 08:16:16 [warn] 16862#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
38
+
39
+ nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
40
+
41
+ 2020/11/09 08:16:16 [emerg] 16862#0: open() "/run/nginx.pid" failed (13: Permission denied)
42
+
43
+ nginx: configuration file /etc/nginx/nginx.conf test failed
44
+
45
+ [ec2-user@ip-172-31-45-251 ~]$
46
+
47
+ ```
48
+
49
+
50
+
51
+
52
+
29
- ### 該当のソースコード
53
+ ###該当のソースコード
30
-
31
-
32
54
 
33
55
  ```
34
56
 
@@ -148,6 +170,88 @@
148
170
 
149
171
 
150
172
 
173
+ ↓修正後のコード
174
+
175
+ ```Nginx
176
+
177
+ upstream app_server {
178
+
179
+ # Unicornと連携させるための設定
180
+
181
+ server unix:/var/www/nostalgia/tmp/sockets/unicorn.sock;
182
+
183
+ }
184
+
185
+
186
+
187
+ # {}で囲った部分をブロックと呼ぶ。サーバの設定ができる
188
+
189
+ server {
190
+
191
+ # このプログラムが接続を受け付けるポート番号
192
+
193
+ listen 80;
194
+
195
+ # 接続を受け付けるリクエストURL ここに書いていないURLではアクセスできない
196
+
197
+ server_name xx.xxx.xx.xx;
198
+
199
+
200
+
201
+ # クライアントからアップロードされてくるファイルの容量の上限を2ギガに設定。デフォルトは1メガなので大きめにしておく
202
+
203
+ client_max_body_size 2g;
204
+
205
+
206
+
207
+ # 接続が来た際のrootディレクトリ
208
+
209
+ root /var/www/nostalgia/public;
210
+
211
+
212
+
213
+ # assetsファイル(CSSやJavaScriptのファイルなど)にアクセスが来た際に適用される設定
214
+
215
+ location ^~ /assets/ {
216
+
217
+ gzip_static on;
218
+
219
+ expires max;
220
+
221
+ add_header Cache-Control public;
222
+
223
+ }
224
+
225
+
226
+
227
+ try_files $uri/index.html $uri @unicorn;
228
+
229
+
230
+
231
+ location @unicorn {
232
+
233
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
234
+
235
+ proxy_set_header Host $http_host;
236
+
237
+ proxy_redirect off;
238
+
239
+ proxy_pass http://app_server;
240
+
241
+ }
242
+
243
+
244
+
245
+ error_page 500 502 503 504 /500.html;
246
+
247
+
248
+
249
+ ```
250
+
251
+
252
+
253
+
254
+
151
255
  ### 試したこと
152
256
 
153
257
  エラーログをみてアプリのIアドレスの入力を間違えていたのかも考え、

2

IPにマスク

2020/11/09 08:18

投稿

yutaro_0529
yutaro_0529

スコア12

test CHANGED
File without changes
test CHANGED
@@ -16,9 +16,9 @@
16
16
 
17
17
  ```
18
18
 
19
- 2020/11/09 01:52:51 [emerg] 12812#0: unknown directive "54.248.24.69" in /etc/nginx/conf.d/rails.conf:14
19
+ 2020/11/09 01:52:51 [emerg] 12812#0: unknown directive "xx.xxx.xx.xx;" in /etc/nginx/conf.d/rails.conf:14
20
20
 
21
- 2020/11/09 05:00:51 [emerg] 15950#0: unknown directive "54.248.24.69" in /etc/nginx/conf.d/rails.conf:14
21
+ 2020/11/09 05:00:51 [emerg] 15950#0: unknown directive "xx.xxx.xx.xx;" in /etc/nginx/conf.d/rails.conf:14
22
22
 
23
23
  /var/log/nginx/error.log (END)
24
24
 

1

IPにマスク

2020/11/09 07:38

投稿

yutaro_0529
yutaro_0529

スコア12

test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  # 接続を受け付けるリクエストURL ここに書いていないURLではアクセスできない
58
58
 
59
- server_name Elastic IP;54.248.24.69
59
+ server_name Elastic IP;xx.xxx.xx.xx;
60
60
 
61
61
 
62
62