質問編集履歴

13

追加

2018/09/16 10:15

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,34 @@
32
32
 
33
33
 
34
34
 
35
+ 関係あるのかがよくわかっていないのですが、
36
+
37
+ `➜ ~ echo -en 'GET / HTTP/1.0\r\n\r\n' | socat stdio /home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock
38
+
39
+ `を叩くと
40
+
41
+
42
+
43
+ ```
44
+
45
+ HTTP/1.1 301 Moved Permanently
46
+
47
+ Date: Sun, 16 Sep 2018 10:14:09 GMT
48
+
49
+ Connection: close
50
+
51
+ Content-Type: text/html
52
+
53
+ Location: https://localhost/
54
+
55
+ Vary: Origin
56
+
57
+ ```
58
+
59
+ と出て来ます。
60
+
61
+
62
+
35
63
  /etc/nginx/conf.d/pecopeco.confは以下です
36
64
 
37
65
  ```

12

追加

2018/09/16 10:15

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -94,6 +94,128 @@
94
94
 
95
95
 
96
96
 
97
+ /etc/nginx/nginx.conf
98
+
99
+ ```
100
+
101
+ # For more information on configuration, see:
102
+
103
+ # * Official English Documentation: http://nginx.org/en/docs/
104
+
105
+ # * Official Russian Documentation: http://nginx.org/ru/docs/
106
+
107
+
108
+
109
+ user nginx;
110
+
111
+ worker_processes auto;
112
+
113
+ error_log /var/log/nginx/error.log;
114
+
115
+ pid /run/nginx.pid;
116
+
117
+
118
+
119
+ # Load dynamic modules. See /usr/share/nginx/README.dynamic.
120
+
121
+ include /usr/share/nginx/modules/*.conf;
122
+
123
+
124
+
125
+ events {
126
+
127
+ worker_connections 1024;
128
+
129
+ }
130
+
131
+
132
+
133
+ http {
134
+
135
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
136
+
137
+ '$status $body_bytes_sent "$http_referer" '
138
+
139
+ '"$http_user_agent" "$http_x_forwarded_for"';
140
+
141
+
142
+
143
+ access_log /var/log/nginx/access.log main;
144
+
145
+
146
+
147
+ sendfile on;
148
+
149
+ tcp_nopush on;
150
+
151
+ tcp_nodelay on;
152
+
153
+ keepalive_timeout 65;
154
+
155
+ types_hash_max_size 2048;
156
+
157
+
158
+
159
+ include /etc/nginx/mime.types;
160
+
161
+ default_type application/octet-stream;
162
+
163
+
164
+
165
+ # Load modular configuration files from the /etc/nginx/conf.d directory.
166
+
167
+ # See http://nginx.org/en/docs/ngx_core_module.html#include
168
+
169
+ # for more information.
170
+
171
+ include /etc/nginx/conf.d/*.conf;
172
+
173
+
174
+
175
+ server {
176
+
177
+ listen 80 default_server;
178
+
179
+ listen [::]:80 default_server;
180
+
181
+ server_name _;
182
+
183
+ root /usr/share/nginx/html;
184
+
185
+
186
+
187
+ # Load configuration files for the default server block.
188
+
189
+ include /etc/nginx/default.d/*.conf;
190
+
191
+
192
+
193
+ location / {
194
+
195
+ }
196
+
197
+
198
+
199
+ error_page 404 /404.html;
200
+
201
+ location = /40x.html {
202
+
203
+ }
204
+
205
+
206
+
207
+ error_page 500 502 503 504 /50x.html;
208
+
209
+ location = /50x.html {
210
+
211
+ }
212
+
213
+ }
214
+
215
+ ```
216
+
217
+
218
+
97
219
  以下ローカルのファイルです。
98
220
 
99
221
 

11

誤字

2018/09/15 10:06

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
@@ -1 +1 @@
1
- unicorn + nginx で作ったec2上のrailsアプリにアクセスすると302 が出て、何も表示されない
1
+ unicorn + nginx で作ったec2上のrailsアプリにアクセスすると301エラーが出て、何も表示されない
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- いうログが書いてあります。。
27
+ , 301エラーのログが書いてあります。。
28
28
 
29
29
 
30
30
 

10

現状修正

2018/09/15 10:01

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
@@ -1 +1 @@
1
- unicorn + nginx で作ったec2上のrailsアプリにアクセスすると、403 Forbidden が出
1
+ unicorn + nginx で作ったec2上のrailsアプリにアクセスすると、302 が出て、何も表示されない。
test CHANGED
@@ -2,53 +2,23 @@
2
2
 
3
3
  webサーバはnginx, appサーバはunicornを使っています。
4
4
 
5
- しかし、ipアドレスに `curl 【ipアドレス】` などでアクセスしても、以下のエラーて来ま
5
+ しかし、ipアドレスに `curl 【ipアドレス】` などでアクセスしても、レスポンス返って来ません
6
-
7
-
8
-
9
- レスポンスには、
6
+
10
-
11
-
12
-
13
- ```
7
+
14
-
15
- <html>
8
+
16
-
17
- <head><title>403 Forbidden</title></head>
9
+
18
-
19
- <body bgcolor="white">
10
+
20
-
21
- <center><h1>403 Forbidden</h1></center>
22
-
23
- <hr><center>nginx/1.12.2</center>
24
-
25
- </body>
26
-
27
- </html>
28
-
29
- ```
30
-
31
- というエラーが出て来ます。
32
-
33
-
34
-
35
- `/home/tomohiroo/pecopeco/shared/log/nginx.error.log` には、
11
+ `/home/tomohiroo/pecopeco/shared/log/nginx.error.log` と `/home/tomohiroo/pecopeco/shared/log/unicorn.log` には、なにも表示されず、
36
12
 
37
13
  (userはtomohiroo, appnameはpecopecoです。)
38
14
 
39
15
 
40
16
 
41
- ```
42
-
43
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public//index.html" failed (13: Permission denied), client: 133.202.241.22, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
44
-
45
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
46
-
47
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
48
-
49
- 2018/09/14 22:42:05 [crit] 31019#0: *643 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock:/", host: "xxx.xxx.xxx.xxx"
50
-
51
- 2018/09/14 22:42:05 [error] 31019#0: *643 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock/", host: "xxx.xxx.xxx.xxx"
17
+ `pecopeco/shared/log/nginx.access.log`
18
+
19
+ ```
20
+
21
+ xxx.xxx.xxx.xxx(クライアントのipアドレス) - - [15/Sep/2018:18:52:13 +0900] "GET / HTTP/1.1" 301 5 "-" "curl/7.54.0"
52
22
 
53
23
  ```
54
24
 
@@ -58,112 +28,90 @@
58
28
 
59
29
 
60
30
 
61
- また、 `curl xxx.xxx.xxx.xxx./hoge` でアクセスすると、エラーログに
62
-
63
-
64
-
65
- ```
66
-
67
- 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge/index.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
68
-
69
- 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
70
-
71
- 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
72
-
73
- 2018/09/15 01:57:19 [crit] 19507#0: *1 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock:/hoge", host: "xxx.xxx.xxx.xxx"
74
-
75
- 2018/09/15 01:57:19 [error] 19507#0: *1 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock/hoge", host: "xxx.xxx.xxx.xxx"
76
-
77
- ```
78
-
79
-
80
-
81
- とでます。
82
-
83
-
84
-
85
31
  どうすれば、アクセスできるのでしょうか?
86
32
 
87
33
 
88
34
 
89
- `/etc/nginx/conf.d/pecopeco.conf`は以下です
35
+ /etc/nginx/conf.d/pecopeco.confは以下です
90
-
36
+
91
- ```
37
+ ```
92
-
38
+
93
- error_log /home/tomohiroo/pecopeco/current/log/nginx.error.log;
39
+ error_log /home/tomohiroo/pecopeco/current/log/nginx.error.log;
94
-
40
+
95
- access_log /home/tomohiroo/pecopeco/current/log/nginx.access.log;
41
+ access_log /home/tomohiroo/pecopeco/current/log/nginx.access.log;
96
-
42
+
97
- client_max_body_size 2G;
43
+ client_max_body_size 2G;
98
-
44
+
99
- upstream app_server {
45
+ upstream app_server {
100
-
46
+
101
- server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock fail_timeout=0;
47
+ server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock fail_timeout=0;
48
+
49
+ }
50
+
51
+ server {
52
+
53
+ listen 80;
54
+
55
+ server_name xx.xxx.xxx.xxx;
56
+
57
+ keepalive_timeout 5;
58
+
59
+ root /home/tomohiroo/pecopeco/current/public;
60
+
61
+ # try_files $uri/index.html $uri.html $uri @app;
62
+
63
+ location / {
64
+
65
+ try_files $uri/index.html $uri.html $uri @app;
102
66
 
103
67
  }
104
68
 
105
- server {
106
-
107
- listen 80;
69
+ location @app {
70
+
108
-
71
+ # HTTP headers
72
+
73
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
74
+
109
- server_name xxx.xxx.xxx.xxx;
75
+ proxy_set_header Host $http_host;
110
-
76
+
111
- keepalive_timeout 5;
77
+ proxy_redirect off;
78
+
79
+ proxy_pass http://app_server;
80
+
81
+ }
82
+
83
+ error_page 500 502 503 504 /500.html;
84
+
85
+ location = /500.html {
112
86
 
113
87
  root /home/tomohiroo/pecopeco/current/public;
114
88
 
115
- try_files $uri/index.html $uri.html $uri @app;
116
-
117
- location @app {
118
-
119
- # HTTP headers
120
-
121
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
122
-
123
- proxy_set_header Host $http_host;
124
-
125
- proxy_redirect off;
126
-
127
- proxy_pass http://app_server;
128
-
129
- }
130
-
131
- error_page 500 502 503 504 /500.html;
132
-
133
- location = /500.html {
134
-
135
- root /home/tomohiroo/pecopeco/current/public;
136
-
137
- }
138
-
139
89
  }
140
90
 
91
+ }
92
+
141
- ```
93
+ ```
94
+
95
+
96
+
142
-
97
+ 以下ローカルのファイルです。
143
-
144
-
98
+
99
+
100
+
145
- また、 `config/unicorn/production.rb` は以下です。
101
+ config/unicorn/production.rb
146
102
 
147
103
  ```
148
104
 
149
105
  $worker = 2
150
106
 
151
- #何秒経過すればワーカーを削除するのかを決める
152
-
153
107
  $timeout = 30
154
108
 
155
109
  $app_dir = "/home/tomohiroo/pecopeco/current"
156
110
 
157
- #リクエストを受け取るポート番号を指定。
158
-
159
111
  $listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir
160
112
 
161
- #PIDの管理ファイルディレクトリ
162
-
163
113
  $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
164
114
 
165
- #エラーログを吐き出すファイルのディレクトリ
166
-
167
115
  $std_log = File.expand_path 'log/unicorn.log', $app_dir
168
116
 
169
117
 
@@ -184,8 +132,6 @@
184
132
 
185
133
 
186
134
 
187
- #ホットデプロイをするかしないかを設定
188
-
189
135
  preload_app true
190
136
 
191
137
 
@@ -222,7 +168,33 @@
222
168
 
223
169
 
224
170
 
171
+ config/Capfile
172
+
173
+ ```
174
+
175
+ require 'capistrano/setup'
176
+
177
+ require 'capistrano/deploy'
178
+
179
+ require 'capistrano/rbenv'
180
+
181
+ require 'capistrano/bundler'
182
+
183
+ require 'capistrano/rails/migrations'
184
+
185
+ require 'capistrano/console'
186
+
187
+ Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
188
+
189
+ require "capistrano/scm/git"
190
+
191
+ install_plugin Capistrano::SCM::Git
192
+
193
+ ```
194
+
195
+
196
+
225
- deploy.rb
197
+ config/deploy.rb
226
198
 
227
199
  ```
228
200
 
@@ -234,7 +206,7 @@
234
206
 
235
207
  set :application, "pecopeco"
236
208
 
237
- set :repo_url, "git@github.com:tomohiroo/pecopeco"
209
+ set :repo_url, "git@github.com:nakamotoo/pecopeco.git"
238
210
 
239
211
  set :branch, 'master'
240
212
 
@@ -328,10 +300,4 @@
328
300
 
329
301
  end
330
302
 
331
-
332
-
333
- # Uncomment the following to require manually verifying the host key before first deploy.
334
-
335
- # set :ssh_options, verify_host_key: :secure
336
-
337
- ```
303
+ ```

9

修正

2018/09/15 10:00

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -46,9 +46,9 @@
46
46
 
47
47
  2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
48
48
 
49
- 2018/09/14 22:42:05 [crit] 31019#0: *643 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock:/", host: "xxx.xxx.xxx.xxx"
50
-
51
- 2018/09/14 22:42:05 [error] 31019#0: *643 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock/", host: "xxx.xxx.xxx.xxx"
49
+ 2018/09/14 22:42:05 [crit] 31019#0: *643 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock:/", host: "xxx.xxx.xxx.xxx"
50
+
51
+ 2018/09/14 22:42:05 [error] 31019#0: *643 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock/", host: "xxx.xxx.xxx.xxx"
52
52
 
53
53
  ```
54
54
 
@@ -70,9 +70,9 @@
70
70
 
71
71
  2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
72
72
 
73
- 2018/09/15 01:57:19 [crit] 19507#0: *1 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock:/hoge", host: "xxx.xxx.xxx.xxx"
74
-
75
- 2018/09/15 01:57:19 [error] 19507#0: *1 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock/hoge", host: "xxx.xxx.xxx.xxx"
73
+ 2018/09/15 01:57:19 [crit] 19507#0: *1 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock:/hoge", host: "xxx.xxx.xxx.xxx"
74
+
75
+ 2018/09/15 01:57:19 [error] 19507#0: *1 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock/hoge", host: "xxx.xxx.xxx.xxx"
76
76
 
77
77
  ```
78
78
 
@@ -98,7 +98,7 @@
98
98
 
99
99
  upstream app_server {
100
100
 
101
- server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock fail_timeout=0;
101
+ server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock fail_timeout=0;
102
102
 
103
103
  }
104
104
 
@@ -142,25 +142,31 @@
142
142
 
143
143
 
144
144
 
145
- また、 `config/unicorn.conf.rb` は以下です。
145
+ また、 `config/unicorn/production.rb` は以下です。
146
-
146
+
147
- ```
147
+ ```
148
-
149
- # set lets
150
148
 
151
149
  $worker = 2
152
150
 
151
+ #何秒経過すればワーカーを削除するのかを決める
152
+
153
153
  $timeout = 30
154
154
 
155
- $app_dir = "/home/tomohiroo/pecopeco"
155
+ $app_dir = "/home/tomohiroo/pecopeco/current"
156
+
156
-
157
+ #リクエストを受け取るポート番号を指定。
158
+
157
- $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir
159
+ $listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir
160
+
161
+ #PIDの管理ファイルディレクトリ
158
162
 
159
163
  $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
160
164
 
165
+ #エラーログを吐き出すファイルのディレクトリ
166
+
161
167
  $std_log = File.expand_path 'log/unicorn.log', $app_dir
162
168
 
163
- # set config
169
+
164
170
 
165
171
  worker_processes $worker
166
172
 
@@ -176,11 +182,13 @@
176
182
 
177
183
  pid $pid
178
184
 
185
+
186
+
179
- # loading booster
187
+ #ホットデプロイをするかしないかを設定
180
188
 
181
189
  preload_app true
182
190
 
183
- # before starting processes
191
+
184
192
 
185
193
  before_fork do |server, worker|
186
194
 
@@ -202,7 +210,7 @@
202
210
 
203
211
  end
204
212
 
205
- # after finishing processes
213
+
206
214
 
207
215
  after_fork do |server, worker|
208
216
 
@@ -211,3 +219,119 @@
211
219
  end
212
220
 
213
221
  ```
222
+
223
+
224
+
225
+ deploy.rb
226
+
227
+ ```
228
+
229
+ # config valid for current version and patch releases of Capistrano
230
+
231
+ lock "~> 3.11.0"
232
+
233
+
234
+
235
+ set :application, "pecopeco"
236
+
237
+ set :repo_url, "git@github.com:tomohiroo/pecopeco"
238
+
239
+ set :branch, 'master'
240
+
241
+ set :deploy_to, '/home/tomohiroo/pecopeco'
242
+
243
+ set :linked_files, %w{config/master.key config/secrets.yml}
244
+
245
+ set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
246
+
247
+ set :keep_releases, 5
248
+
249
+ set :rbenv_ruby, '2.5.1'
250
+
251
+ set :log_level, :debug
252
+
253
+ set :repo_tree, 'server'
254
+
255
+ set :default_env, { JAVA_HOME: "/usr/java/jdk1.8.0_181-amd64" }
256
+
257
+
258
+
259
+ namespace :deploy do
260
+
261
+
262
+
263
+ desc 'Restart application'
264
+
265
+ task :restart do
266
+
267
+ invoke 'unicorn:restart'
268
+
269
+ end
270
+
271
+
272
+
273
+ desc 'Create database'
274
+
275
+ task :db_create do
276
+
277
+ on roles(:db) do |host|
278
+
279
+ with rails_env: fetch(:rails_env) do
280
+
281
+ within current_path do
282
+
283
+ execute :bundle, :exec, :rake, 'db:create'
284
+
285
+ end
286
+
287
+ end
288
+
289
+ end
290
+
291
+ end
292
+
293
+
294
+
295
+ desc 'Run seed'
296
+
297
+ task :seed do
298
+
299
+ on roles(:app) do
300
+
301
+ with rails_env: fetch(:rails_env) do
302
+
303
+ within current_path do
304
+
305
+ execute :bundle, :exec, :rake, 'db:seed_fu'
306
+
307
+ end
308
+
309
+ end
310
+
311
+ end
312
+
313
+ end
314
+
315
+
316
+
317
+ after :publishing, :restart
318
+
319
+
320
+
321
+ after :restart, :clear_cache do
322
+
323
+ on roles(:web), in: :groups, limit: 3, wait: 10 do
324
+
325
+ end
326
+
327
+ end
328
+
329
+ end
330
+
331
+
332
+
333
+ # Uncomment the following to require manually verifying the host key before first deploy.
334
+
335
+ # set :ssh_options, verify_host_key: :secure
336
+
337
+ ```

8

追加

2018/09/15 08:52

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -139,3 +139,75 @@
139
139
  }
140
140
 
141
141
  ```
142
+
143
+
144
+
145
+ また、 `config/unicorn.conf.rb` は以下です。
146
+
147
+ ```
148
+
149
+ # set lets
150
+
151
+ $worker = 2
152
+
153
+ $timeout = 30
154
+
155
+ $app_dir = "/home/tomohiroo/pecopeco"
156
+
157
+ $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir
158
+
159
+ $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
160
+
161
+ $std_log = File.expand_path 'log/unicorn.log', $app_dir
162
+
163
+ # set config
164
+
165
+ worker_processes $worker
166
+
167
+ working_directory $app_dir
168
+
169
+ stderr_path $std_log
170
+
171
+ stdout_path $std_log
172
+
173
+ timeout $timeout
174
+
175
+ listen $listen
176
+
177
+ pid $pid
178
+
179
+ # loading booster
180
+
181
+ preload_app true
182
+
183
+ # before starting processes
184
+
185
+ before_fork do |server, worker|
186
+
187
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
188
+
189
+ old_pid = "#{server.config[:pid]}.oldbin"
190
+
191
+ if old_pid != server.pid
192
+
193
+ begin
194
+
195
+ Process.kill "QUIT", File.read(old_pid).to_i
196
+
197
+ rescue Errno::ENOENT, Errno::ESRCH
198
+
199
+ end
200
+
201
+ end
202
+
203
+ end
204
+
205
+ # after finishing processes
206
+
207
+ after_fork do |server, worker|
208
+
209
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
210
+
211
+ end
212
+
213
+ ```

7

誤りの修正

2018/09/15 04:18

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
@@ -1 +1 @@
1
- unicorn + nginx で作ったec2上のrailsアプリにアクセスすると、public/配下にアクセスされ、403 Forbidden が出る
1
+ unicorn + nginx で作ったec2上のrailsアプリにアクセスすると、403 Forbidden が出る
test CHANGED
@@ -80,8 +80,6 @@
80
80
 
81
81
  とでます。
82
82
 
83
- なぜかpublic.hoge/index.htmlを取りに行ってしまっているようです。
84
-
85
83
 
86
84
 
87
85
  どうすれば、アクセスできるのでしょうか?

6

補足情報

2018/09/14 17:22

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
@@ -1 +1 @@
1
- unicorn + nginx で作ったec2上のrailsアプリにアクセスしても、403 Forbidden が出る
1
+ unicorn + nginx で作ったec2上のrailsアプリにアクセスするとpublic/配下にアクセスされ、403 Forbidden が出る
test CHANGED
@@ -40,19 +40,47 @@
40
40
 
41
41
  ```
42
42
 
43
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public//index.html" failed (13: Permission denied), client: 133.202.241.22, server: 【ipアドレス】, request: "GET / HTTP/1.1", host: "【ipアドレス】"
43
+ 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public//index.html" failed (13: Permission denied), client: 133.202.241.22, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
44
44
 
45
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/.html" failed (13: Permission denied), client: 【ipアドレス】, server: 【ipアドレス】, request: "GET / HTTP/1.1", host: "【ipアドレス】"
45
+ 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
46
46
 
47
- 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/" failed (13: Permission denied), client: 【ipアドレス】, server: 【ipアドレス】, request: "GET / HTTP/1.1", host: "【ipアドレス】"
47
+ 2018/09/14 22:42:05 [crit] 31019#0: *643 stat() "/home/tomohiroo/pecopeco/current/public/" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", host: "xxx.xxx.xxx.xxx"
48
48
 
49
- 2018/09/14 22:42:05 [crit] 31019#0: *643 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock failed (13: Permission denied) while connecting to upstream, client: 【ipアドレス】, server: 【ipアドレス】, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock:/", host: "【ipアドレス】"
49
+ 2018/09/14 22:42:05 [crit] 31019#0: *643 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock:/", host: "xxx.xxx.xxx.xxx"
50
50
 
51
- 2018/09/14 22:42:05 [error] 31019#0: *643 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: 【ipアドレス】, server: 【ipアドレス】, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock/", host: "【ipアドレス】"
51
+ 2018/09/14 22:42:05 [error] 31019#0: *643 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock/", host: "xxx.xxx.xxx.xxx"
52
52
 
53
53
  ```
54
54
 
55
+
56
+
55
57
  というログが書いてあります。。
58
+
59
+
60
+
61
+ また、 `curl xxx.xxx.xxx.xxx./hoge` でアクセスすると、エラーログに
62
+
63
+
64
+
65
+ ```
66
+
67
+ 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge/index.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
68
+
69
+ 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
70
+
71
+ 2018/09/15 01:57:19 [crit] 19507#0: *1 stat() "/home/tomohiroo/pecopeco/current/public/hoge" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", host: "xxx.xxx.xxx.xxx"
72
+
73
+ 2018/09/15 01:57:19 [crit] 19507#0: *1 connect() to unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock failed (13: Permission denied) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock:/hoge", host: "xxx.xxx.xxx.xxx"
74
+
75
+ 2018/09/15 01:57:19 [error] 19507#0: *1 open() "/home/tomohiroo/pecopeco/current/public/500.html" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /hoge HTTP/1.1", upstream: "http://unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock/hoge", host: "xxx.xxx.xxx.xxx"
76
+
77
+ ```
78
+
79
+
80
+
81
+ とでます。
82
+
83
+ なぜかpublic.hoge/index.htmlを取りに行ってしまっているようです。
56
84
 
57
85
 
58
86
 
@@ -80,7 +108,7 @@
80
108
 
81
109
  listen 80;
82
110
 
83
- server_name 【ipアドレス】;
111
+ server_name xxx.xxx.xxx.xxx;
84
112
 
85
113
  keepalive_timeout 5;
86
114
 

5

秘密消した

2018/09/14 17:03

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -80,7 +80,7 @@
80
80
 
81
81
  listen 80;
82
82
 
83
- server_name 13.230.227.127;
83
+ server_name 【ipアドレス】;
84
84
 
85
85
  keepalive_timeout 5;
86
86
 

4

confの追加

2018/09/14 14:11

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -57,3 +57,59 @@
57
57
 
58
58
 
59
59
  どうすれば、アクセスできるのでしょうか?
60
+
61
+
62
+
63
+ `/etc/nginx/conf.d/pecopeco.conf`は以下です。
64
+
65
+ ```
66
+
67
+ error_log /home/tomohiroo/pecopeco/current/log/nginx.error.log;
68
+
69
+ access_log /home/tomohiroo/pecopeco/current/log/nginx.access.log;
70
+
71
+ client_max_body_size 2G;
72
+
73
+ upstream app_server {
74
+
75
+ server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/.unicorn.sock fail_timeout=0;
76
+
77
+ }
78
+
79
+ server {
80
+
81
+ listen 80;
82
+
83
+ server_name 13.230.227.127;
84
+
85
+ keepalive_timeout 5;
86
+
87
+ root /home/tomohiroo/pecopeco/current/public;
88
+
89
+ try_files $uri/index.html $uri.html $uri @app;
90
+
91
+ location @app {
92
+
93
+ # HTTP headers
94
+
95
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
96
+
97
+ proxy_set_header Host $http_host;
98
+
99
+ proxy_redirect off;
100
+
101
+ proxy_pass http://app_server;
102
+
103
+ }
104
+
105
+ error_page 500 502 503 504 /500.html;
106
+
107
+ location = /500.html {
108
+
109
+ root /home/tomohiroo/pecopeco/current/public;
110
+
111
+ }
112
+
113
+ }
114
+
115
+ ```

3

題名変更

2018/09/14 14:11

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
@@ -1 +1 @@
1
- aws上のrailsアプリにアクセスしても、403 Forbidden が出る
1
+ unicorn + nginx で作ったec2上のrailsアプリにアクセスしても、403 Forbidden が出る
test CHANGED
File without changes

2

誤字

2018/09/14 14:01

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- railsアプリを、capistranoを使ってaws ec3にデプロイしました。
1
+ railsアプリを、capistranoを使ってaws ec2にデプロイしました。
2
2
 
3
3
  webサーバはnginx, appサーバはunicornを使っています。
4
4
 

1

詳細を追加。

2018/09/14 13:58

投稿

tomohiroo
tomohiroo

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- railsアプリを、capistranoを使ってデプロイしました。
1
+ railsアプリを、capistranoを使ってaws ec3にデプロイしました。
2
2
 
3
3
  webサーバはnginx, appサーバはunicornを使っています。
4
4