ブラウザから http://hogehoge.com/hogehoge/index.rb を実行
open_uri を用いて'https://hogehoge.jp/hogehoge.cgi' からデータを受け取る
-> エラー
ruby
1http://hogehoge.com/hogehoge/index.rb 2 3#!/usr/local/bin/rbenv/shims/ruby 4puts "Content-type: text/html\n\n" # ヘッダ(データの情報)を出力 5puts # 仕切りとして、空行を出力 6 7cgi = 'https://hogehoge.jp/hogehoge.cgi' 8require 'open-uri' 9io = OpenURI.open_uri(cgi) 10puts io.read
以下の様なエラーログがありました。
/etc/httpd/logs/error_log [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/net/http.rb:906:in `rescue in block in connect' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] : [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] Failed to open TCP connection to hogehoge.jp:443 (Permission denied - connect(2) for "hogehoge.jp" port 443) [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] ( [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] Errno::EACCES [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] ) [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/net/http.rb:903:in `block in connect' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/timeout.rb:93:in `block in timeout' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/timeout.rb:103:in `timeout' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/net/http.rb:902:in `connect' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/net/http.rb:887:in `do_start' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/net/http.rb:876:in `start' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:323:in `open_http' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:741:in `buffer_open' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:212:in `block in open_loop' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:210:in `catch' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:210:in `open_loop' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /usr/local/bin/rbenv/versions/2.4.2/lib/ruby/2.4.0/open-uri.rb:151:in `open_uri' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /var/www/html/hogehoge/index.rb:117:in `url' [Mon Oct 23 oo:oo:oo 2017] [error] [client ooo.oo.ooo.oo] \tfrom /var/www/html/hogehoge/index.rb:120:in `<main>'
ターミナルで hogehoge.com のサーバに接続して $ ruby index.rb を実行すると 問題なく取得できました。
$ ruby index.rb
何が原因でしょうか。
回答3件
あなたの回答
tips
プレビュー