我有一个奇怪的问题
我在本地机器上成功地运行了以下命令。
uri = URI('http://IP/XXX/XXX.php')
res = Net::HTTP.post_form(uri, 'account' => Settings.account, 'orderno' => order.order_no, 'order_money' => order.total_price, 'order_user' => order.name )
成功消息如下
#<Net::HTTPOK 200 OK readbody=true>
但是,在远程部署到生产机器之后。使用相同代码
我收到错误信息如下
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `initialize'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:582:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:506:in `post_form'
我找到了一些解决方案,比如
- 为nethttp请求设置更长的超时
- 使用一些gme,如faraday、httpclient
但我不知道它们是否是一些好的解决方案。
此外,我想这可能是服务器配置问题。
因此,我尝试确保生产服务器能够连接到目标服务器。
sudo traceroute -w 1 -n -T IP
我有这些,看起来不错吗?
traceroute to OOO.XXX.YYY (IP), 30 hops max, 60 byte packets
1 66.212.30.225 0.564 ms 0.599 ms 0.680 ms
2 96.44.180.41 66.869 ms 66.873 ms 67.103 ms
3 66.186.197.173 4.233 ms 4.248 ms 4.300 ms
4 206.223.143.104 0.656 ms 0.730 ms 0.798 ms
5 60.199.17.57 143.147 ms 143.135 ms 143.133 ms
6 60.199.18.157 143.067 ms 143.057 ms 143.020 ms
7 60.199.3.221 143.014 ms 142.997 ms 142.982 ms
8 60.199.3.142 142.994 ms 60.199.20.221 182.958 ms 60.199.23.14 143.085 ms
9 60.199.17.118 143.338 ms 60.199.17.114 143.199 ms 60.199.17.118 143.153 ms
10 219.80.114.86 145.561 ms 145.662 ms 145.608 ms
11 211.79.200.42 145.508 ms 145.517 ms 145.473 ms
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
此外,我将邮件发送到目的地服务器,确保我遵守投递规则。
我尽力修复这个错误,但是。。。。它仍然存在~~
问题解决了。。。。。
关键是目标服务器阻止了来自其他国家的IP。
因此,我要求他们为我们设置白名单,然后问题解决了。