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

質問編集履歴

8

質問の内容を大幅に変更、結論を前方に要約しました。

2019/10/17 06:27

投稿

begenner
begenner

スコア80

title CHANGED
@@ -1,1 +1,1 @@
1
- Rails + AWS でHTTPSに対応させたい(nginx 403 Forbidden エラー)
1
+ Rails + AWS + nginxエラー(nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf)
body CHANGED
@@ -7,27 +7,27 @@
7
7
  2. [Amazon Linux2とLet's EncryptでSSL対応サーバを0から爆速構築 - Qiita](https://qiita.com/MysteriousMonky/items/4d3d857c0e68d4bfff39)
8
8
 
9
9
  を参考にしました。
10
- しかし上記タイトルのエラーが発生したため、他のサイトを探しましたが、
10
+ しかし上記タイトルのエラーが発生したため、他のサイトを探しましたが、該当するような記事が見つからなかったため、
11
+ nginxの設定ファイルをどのように編集すればいいか全くわかりません(m_ _m)
12
+ もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m_ _m)
11
13
 
12
- - 設定がどれも微妙に違う
13
- - 添削の仕方がわからない(nginxに関しては初心者です)
14
14
 
15
+ ## *結論(解決策)
16
+ 上記の2 で実行、反映された状態で
15
- であるためnginxの設定ファイルをどのように編集すればいいか全くわかりません(m_ _m)
17
+ `/etc/nginx/conf.d/webapp.conf` 内に
16
- もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m_ _m)
18
+ `include /etc/letsencrypt/options-ssl-nginx.conf;`
19
+ という行があり(追加され)、
17
20
 
18
- ### デプロイ、HTTPS対応させるために参考にしてきたサイト
19
- 1. アプリのデプロイまで
20
- [(デプロイ編②)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで - Qiita](https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1)
21
+ `/etc/nginx/conf.d/webapp.conf`の`ssl_protocols TLSv1 TLSv1.1 TLSv1.2;`
21
22
 
22
- 2. HTTPS対応のために参考にした記事(2つ)
23
- [[Rails][Nginx][AWS] Let's EncryptをEC2上のRailsに入れてHttpsにする - Qiita](https://qiita.com/Masahiro_T/items/9b81b31b3c21bd03fc09)
24
- [Amazon Linux2とLet's EncryptでSSL対応サーバを0から爆速構築 - Qiita](https://qiita.com/MysteriousMonky/items/4d3d857c0e68d4bfff39)
23
+ `/etc/letsencrypt/options-ssl-nginx.conf`の `ssl_protocols TLSv1.2;`
24
+ で重複が発生していたため `warning`が発生していました。
25
25
 
26
- 3. nginx設定ファイルの参考にしたサイト
27
- [RailsアプリをAWS EC2で公開する超簡単な手順 【独自ドメイン/HTTPS対応】 - ひろこま Hack Log](https://www.mahirokazuko.com/entry/2018/09/11/112010)
26
+ `/etc/nginx/conf.d/webapp.conf`の`ssl_protocols TLSv1 TLSv1.1 TLSv1.2;`
27
+ の行をコメントアウト(もしくは)削除することで`warning`は発生しなくなりました。
28
+ 経緯は回答の方にあります。
28
29
 
29
- 4. nginxとunicornの設定について(これを利用して編集はしていません)
30
- [【Ruby on Rails】Nginxとunicornを使ってHTTPS(SSL)対応する方法 | Y-hilite](https://y-hilite.com/2908/)
30
+ [yu_1985](https://teratail.com/users/yu_1985#reply)さん、本当にありがとうございました!!
31
31
 
32
32
  ### 動作環境
33
33
  Rails
@@ -52,38 +52,11 @@
52
52
 
53
53
 
54
54
  ### エラー内容
55
- 1. nginx を再起動してブラウザにアクセスすると`nginx 403 Forbidden`が発生
56
- 2. 下記の設定ファイルを保存し`sudo nginx -t`を実行した時`[warn] duplicate value "TLSv1.2"`と警告が出る
55
+ - 下記の設定ファイルを保存し`sudo nginx -t`を実行した時`[warn] duplicate value "TLSv1.2"`と警告が出る
57
56
  (ファイルに同じ文字列は存在しない)
58
- 3. `/var/www/rails/webapp/log/nginx.error.log`を確認すると下記のエラーが表示されている
59
- ```bash
60
- [error] 28121#0: *1 directory index of "/var/www/rails/webapp/public/" is forbidden, client: 211.1.206.206, server: domainName, request: "GET / HTTP/1.1", host: "domainName"
61
- ```
62
57
 
63
- - /etc/nginx/ 配下の構成は下記のようになっています
64
- ```bash
65
- conf.d # ディレクトリ
66
- default.d # ディレクトリ
67
- fastcgi.conf
68
- fastcgi.conf.default
69
- fastcgi_params
70
- fastcgi_params.default
71
- koi-utf
72
- koi-win
73
- mime.types
74
- mime.types.default
75
- nginx.conf
76
- nginx.conf.default
77
- scgi_params
78
- scgi_params.default
79
- uwsgi_params
80
- uwsgi_params.default
81
- win-utf
82
- ```
83
58
 
84
59
 
85
-
86
-
87
60
  ### nginxのシンタックスチェック、再起動後のステータス確認結果
88
61
  ```bash
89
62
  [username@ip-xxx-xxx-xxx-xxx ~]$ sudo nginx -t
@@ -277,28 +250,4 @@
277
250
  server_name domainName;
278
251
  return 301 https://$host$request_uri;
279
252
  }
280
- ```
253
+ ```
281
-
282
- ### 追記1(権限関係の確認)
283
- ```bash
284
- [username@ip-xxx-xxx-xxx-xxx ~]$ cd /;ls -la
285
- # drwx-----x 20 username username 280 10月 4 13:44 var
286
-
287
- [username@ip-xxx-xxx-xxx-xxx ~]$ cd /var/;ls -la
288
- # drwx-----x 4 username username 38 10月 14 17:45 www
289
-
290
- [username@ip-xxx-xxx-xxx-xxx ~]$ cd /www/;ls -la
291
- # drwx-----x 3 username username 43 10月 4 14:12 rails
292
-
293
- [username@ip-xxx-xxx-xxx-xxx ~]$ cd /rails/;ls -la
294
- # drwxrwxrwx 15 username username 302 10月 14 14:03 webapp
295
-
296
- [username@ip-xxx-xxx-xxx-xxx ~]$ cd /webapp/;ls -la
297
- # drwxrwxrwx 15 username username 302 10月 14 14:03 public
298
- ```
299
-
300
-
301
-
302
- ### 追記2
303
- httpsでURLにアクセス -> httpでURLにアクセス すると下記の状態が表示されます
304
- ![イメージ説明](843dc5b59f02e91181b703dfec06f82a.png)

7

httpでURLにアクセスした場合の画像を追加しました

2019/10/17 06:27

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -279,7 +279,7 @@
279
279
  }
280
280
  ```
281
281
 
282
- ### 追記(権限関係の確認)
282
+ ### 追記1(権限関係の確認)
283
283
  ```bash
284
284
  [username@ip-xxx-xxx-xxx-xxx ~]$ cd /;ls -la
285
285
  # drwx-----x 20 username username 280 10月 4 13:44 var
@@ -295,4 +295,10 @@
295
295
 
296
296
  [username@ip-xxx-xxx-xxx-xxx ~]$ cd /webapp/;ls -la
297
297
  # drwxrwxrwx 15 username username 302 10月 14 14:03 public
298
- ```
298
+ ```
299
+
300
+
301
+
302
+ ### 追記2
303
+ httpsでURLにアクセス -> httpでURLにアクセス すると下記の状態が表示されます
304
+ ![イメージ説明](843dc5b59f02e91181b703dfec06f82a.png)

6

webapp 関連のファイル権限を追記しました

2019/10/17 02:58

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -277,4 +277,22 @@
277
277
  server_name domainName;
278
278
  return 301 https://$host$request_uri;
279
279
  }
280
+ ```
281
+
282
+ ### 追記(権限関係の確認)
283
+ ```bash
284
+ [username@ip-xxx-xxx-xxx-xxx ~]$ cd /;ls -la
285
+ # drwx-----x 20 username username 280 10月 4 13:44 var
286
+
287
+ [username@ip-xxx-xxx-xxx-xxx ~]$ cd /var/;ls -la
288
+ # drwx-----x 4 username username 38 10月 14 17:45 www
289
+
290
+ [username@ip-xxx-xxx-xxx-xxx ~]$ cd /www/;ls -la
291
+ # drwx-----x 3 username username 43 10月 4 14:12 rails
292
+
293
+ [username@ip-xxx-xxx-xxx-xxx ~]$ cd /rails/;ls -la
294
+ # drwxrwxrwx 15 username username 302 10月 14 14:03 webapp
295
+
296
+ [username@ip-xxx-xxx-xxx-xxx ~]$ cd /webapp/;ls -la
297
+ # drwxrwxrwx 15 username username 302 10月 14 14:03 public
280
298
  ```

5

エラー内容に log/nginx.error.log の内容を追記しました

2019/10/16 22:15

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -55,6 +55,10 @@
55
55
  1. nginx を再起動してブラウザにアクセスすると`nginx 403 Forbidden`が発生
56
56
  2. 下記の設定ファイルを保存し`sudo nginx -t`を実行した時`[warn] duplicate value "TLSv1.2"`と警告が出る
57
57
  (ファイルに同じ文字列は存在しない)
58
+ 3. `/var/www/rails/webapp/log/nginx.error.log`を確認すると下記のエラーが表示されている
59
+ ```bash
60
+ [error] 28121#0: *1 directory index of "/var/www/rails/webapp/public/" is forbidden, client: 211.1.206.206, server: domainName, request: "GET / HTTP/1.1", host: "domainName"
61
+ ```
58
62
 
59
63
  - /etc/nginx/ 配下の構成は下記のようになっています
60
64
  ```bash

4

ファイル内容の順番を入れ替えました

2019/10/16 14:10

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -56,8 +56,6 @@
56
56
  2. 下記の設定ファイルを保存し`sudo nginx -t`を実行した時`[warn] duplicate value "TLSv1.2"`と警告が出る
57
57
  (ファイルに同じ文字列は存在しない)
58
58
 
59
-
60
- ### 追記1
61
59
  - /etc/nginx/ 配下の構成は下記のようになっています
62
60
  ```bash
63
61
  conf.d # ディレクトリ
@@ -79,8 +77,44 @@
79
77
  win-utf
80
78
  ```
81
79
 
80
+
81
+
82
+
82
- - ファイル`/etc/nginx/nginx.conf`は下記設定になっています
83
+ ### nginxのシンタックスチェック、再起動後のステータス確認結果
83
84
  ```bash
85
+ [username@ip-xxx-xxx-xxx-xxx ~]$ sudo nginx -t
86
+ # nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
87
+ # nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
88
+ # nginx: configuration file /etc/nginx/nginx.conf test is successful
89
+
90
+
91
+ [username@ip-xxx-xxx-xxx-xxx ~]$ sudo service nginx restart
92
+ # Redirecting to /bin/systemctl restart nginx.service
93
+
94
+
95
+ [username@ip-xxx-xxx-xxx-xxx ~]$ sudo service nginx status
96
+ # Redirecting to /bin/systemctl status nginx.service
97
+ # ● nginx.service - The nginx HTTP and reverse proxy server
98
+ # Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
99
+ # Active: active (running) since 火 2019-10-15 23:08:09 JST; 4s ago
100
+ # Process: 11316 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
101
+ # Process: 11313 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
102
+ # Process: 11311 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
103
+ # Main PID: 11319 (nginx)
104
+ # CGroup: /system.slice/nginx.service
105
+ # ├─11319 nginx: master process /usr/sbin/nginx
106
+ # └─11320 nginx: worker process
107
+ #
108
+ # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal systemd[1]: Starting The nginx HTTP and reverse proxy server...
109
+ # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
110
+ # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
111
+ # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: configuration file /etc/nginx/nginx.conf test is successful
112
+ # 10月 15 23:08:09 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11316]: nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
113
+ # 10月 15 23:08:09 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal systemd[1]: Started The nginx HTTP and reverse proxy server.
114
+ ```
115
+
116
+ ### nginxの設定ファイル1(/etc/nginx/nginx.conf)
117
+ ```bash
84
118
  # For more information on configuration, see:
85
119
  # * Official English Documentation: http://nginx.org/en/docs/
86
120
  # * Official Russian Documentation: http://nginx.org/ru/docs/
@@ -171,40 +205,8 @@
171
205
  ```
172
206
 
173
207
 
174
- ### nginxのシンタックスチェック、再起動後のステータス確認結果
175
- ```bash
176
- [username@ip-xxx-xxx-xxx-xxx ~]$ sudo nginx -t
177
- # nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
178
- # nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
179
- # nginx: configuration file /etc/nginx/nginx.conf test is successful
180
208
 
181
-
182
- [username@ip-xxx-xxx-xxx-xxx ~]$ sudo service nginx restart
183
- # Redirecting to /bin/systemctl restart nginx.service
184
-
185
-
186
- [username@ip-xxx-xxx-xxx-xxx ~]$ sudo service nginx status
187
- # Redirecting to /bin/systemctl status nginx.service
188
- # ● nginx.service - The nginx HTTP and reverse proxy server
189
- # Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
190
- # Active: active (running) since 火 2019-10-15 23:08:09 JST; 4s ago
191
- # Process: 11316 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
192
- # Process: 11313 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
193
- # Process: 11311 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
194
- # Main PID: 11319 (nginx)
195
- # CGroup: /system.slice/nginx.service
196
- # ├─11319 nginx: master process /usr/sbin/nginx
197
- # └─11320 nginx: worker process
198
- #
199
- # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal systemd[1]: Starting The nginx HTTP and reverse proxy server...
200
- # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
201
- # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
202
- # 10月 15 23:08:08 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11313]: nginx: configuration file /etc/nginx/nginx.conf test is successful
203
- # 10月 15 23:08:09 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal nginx[11316]: nginx: [warn] duplicate value "TLSv1.2" in /etc/nginx/conf.d/webapp.conf:66
204
- # 10月 15 23:08:09 ip-xxx-xxx-xxx-xxx.ap-northeast-1.compute.internal systemd[1]: Started The nginx HTTP and reverse proxy server.
205
- ```
206
-
207
- ### nginxの設定ファイル(/etc/nginx/conf.d/webapp.conf)
209
+ ### nginxの設定ファイル2(/etc/nginx/conf.d/webapp.conf)
208
210
  ```bash
209
211
  ```bash
210
212
  # /etc/nginx/conf.d/webapp.conf

3

追記依頼の内容を追記しました

2019/10/16 13:35

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -56,6 +56,121 @@
56
56
  2. 下記の設定ファイルを保存し`sudo nginx -t`を実行した時`[warn] duplicate value "TLSv1.2"`と警告が出る
57
57
  (ファイルに同じ文字列は存在しない)
58
58
 
59
+
60
+ ### 追記1
61
+ - /etc/nginx/ 配下の構成は下記のようになっています
62
+ ```bash
63
+ conf.d # ディレクトリ
64
+ default.d # ディレクトリ
65
+ fastcgi.conf
66
+ fastcgi.conf.default
67
+ fastcgi_params
68
+ fastcgi_params.default
69
+ koi-utf
70
+ koi-win
71
+ mime.types
72
+ mime.types.default
73
+ nginx.conf
74
+ nginx.conf.default
75
+ scgi_params
76
+ scgi_params.default
77
+ uwsgi_params
78
+ uwsgi_params.default
79
+ win-utf
80
+ ```
81
+
82
+ - ファイル`/etc/nginx/nginx.conf`は下記の設定になっています
83
+ ```bash
84
+ # For more information on configuration, see:
85
+ # * Official English Documentation: http://nginx.org/en/docs/
86
+ # * Official Russian Documentation: http://nginx.org/ru/docs/
87
+
88
+ user nginx;
89
+ worker_processes auto;
90
+ error_log /var/log/nginx/error.log;
91
+ pid /run/nginx.pid;
92
+
93
+ # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
94
+ include /usr/share/nginx/modules/*.conf;
95
+
96
+ events {
97
+ worker_connections 1024;
98
+ }
99
+
100
+ http {
101
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
102
+ '$status $body_bytes_sent "$http_referer" '
103
+ '"$http_user_agent" "$http_x_forwarded_for"';
104
+
105
+ access_log /var/log/nginx/access.log main;
106
+
107
+ sendfile on;
108
+ tcp_nopush on;
109
+ tcp_nodelay on;
110
+ keepalive_timeout 65;
111
+ types_hash_max_size 2048;
112
+
113
+ include /etc/nginx/mime.types;
114
+ default_type application/octet-stream;
115
+
116
+ # Load modular configuration files from the /etc/nginx/conf.d directory.
117
+ # See http://nginx.org/en/docs/ngx_core_module.html#include
118
+ # for more information.
119
+ include /etc/nginx/conf.d/*.conf;
120
+
121
+ server {
122
+ listen 80 default_server;
123
+ listen [::]:80 default_server;
124
+ server_name _;
125
+ root /usr/share/nginx/html;
126
+
127
+ # Load configuration files for the default server block.
128
+ include /etc/nginx/default.d/*.conf;
129
+
130
+ location / {
131
+ }
132
+
133
+ error_page 404 /404.html;
134
+ location = /40x.html {
135
+ }
136
+
137
+ error_page 500 502 503 504 /50x.html;
138
+ location = /50x.html {
139
+ }
140
+ }
141
+
142
+ # Settings for a TLS enabled server.
143
+ #
144
+ # server {
145
+ # listen 443 ssl http2 default_server;
146
+ # listen [::]:443 ssl http2 default_server;
147
+ # server_name _;
148
+ # root /usr/share/nginx/html;
149
+ #
150
+ # ssl_certificate "/etc/pki/nginx/server.crt";
151
+ # ssl_certificate_key "/etc/pki/nginx/private/server.key";
152
+ # ssl_session_cache shared:SSL:1m;
153
+ # ssl_session_timeout 10m;
154
+ # ssl_ciphers HIGH:!aNULL:!MD5;
155
+ # ssl_prefer_server_ciphers on;
156
+ #
157
+ # # Load configuration files for the default server block.
158
+ # include /etc/nginx/default.d/*.conf;
159
+ #
160
+ # location / {
161
+ # }
162
+ #
163
+ # error_page 404 /404.html;
164
+ # location = /40x.html {
165
+ # }
166
+ #
167
+ # error_page 500 502 503 504 /50x.html;
168
+ # location = /50x.html {
169
+ # }
170
+ # }
171
+ ```
172
+
173
+
59
174
  ### nginxのシンタックスチェック、再起動後のステータス確認結果
60
175
  ```bash
61
176
  [username@ip-xxx-xxx-xxx-xxx ~]$ sudo nginx -t

2

タイトルを変更しました

2019/10/16 03:03

投稿

begenner
begenner

スコア80

title CHANGED
@@ -1,1 +1,1 @@
1
- Rails + AWS でHTTPS対応をしたい(nginx 403 Forbidden エラー)
1
+ Rails + AWS でHTTPS対応させたい(nginx 403 Forbidden エラー)
body CHANGED
File without changes

1

参考にしてきたサイトを追加しました

2019/10/15 14:55

投稿

begenner
begenner

スコア80

title CHANGED
File without changes
body CHANGED
@@ -15,6 +15,20 @@
15
15
  であるためnginxの設定ファイルをどのように編集すればいいか全くわかりません(m_ _m)
16
16
  もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m_ _m)
17
17
 
18
+ ### デプロイ、HTTPS対応させるために参考にしてきたサイト
19
+ 1. アプリのデプロイまで
20
+ [(デプロイ編②)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで - Qiita](https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1)
21
+
22
+ 2. HTTPS対応のために参考にした記事(2つ)
23
+ [[Rails][Nginx][AWS] Let's EncryptをEC2上のRailsに入れてHttpsにする - Qiita](https://qiita.com/Masahiro_T/items/9b81b31b3c21bd03fc09)
24
+ [Amazon Linux2とLet's EncryptでSSL対応サーバを0から爆速構築 - Qiita](https://qiita.com/MysteriousMonky/items/4d3d857c0e68d4bfff39)
25
+
26
+ 3. nginx設定ファイルの参考にしたサイト
27
+ [RailsアプリをAWS EC2で公開する超簡単な手順 【独自ドメイン/HTTPS対応】 - ひろこま Hack Log](https://www.mahirokazuko.com/entry/2018/09/11/112010)
28
+
29
+ 4. nginxとunicornの設定について(これを利用して編集はしていません)
30
+ [【Ruby on Rails】Nginxとunicornを使ってHTTPS(SSL)対応する方法 | Y-hilite](https://y-hilite.com/2908/)
31
+
18
32
  ### 動作環境
19
33
  Rails
20
34
  - Ruby: 2.4.5