Curl error : No route to host
Curl error : No route to host
所以我们正在 PHP 中构建一个 Web 应用程序,我们正在尝试向外部 API 发出请求。问题是我们收到卷曲错误:
cURL error 7: Failed to connect to external.api.com port 443: No route to host
现在介绍一些背景知识。
- 我们正在使用 Guzzle 发出请求。
- 我们在 Apache 上托管,它在 Linux 机器上 运行ning 并且我们也在使用 SSL。
- API 也在使用 SSL,因此错误消息中的端口 443。
- HTTP 请求包含用于身份验证的证书。
我已经设法在两个不同的开发环境中 运行 获得它,但在生产环境中却没有。我怀疑问题出在 Apache 的配置上,好像我们还没有让它可以向特定 IP 或端口发出请求。我不知道如何检查它。我读到我可能必须更改文件 /etc/network/interface,但我还没有找到任何关于在那里写什么的信息。
我也读过我必须 运行 $ netstat -rn
才能找到答案,但我不确定在那里看什么。
编辑:
没有任何参数和任何东西,甚至无法发出简单的 get 请求。
但是我可以向 https://google.com and https://facebook.com 提出请求。过几会再写。
netstat -aln | grep 443
将显示您的网络服务器是否正在侦听该端口。
根据您安装配置文件的网络服务器,站点将位于 /etc/nginx/sites-available/default
、/etc/nginx/sites-available/yourSite
、/etc/nginx/nginx.conf
或其他类似的 apache 路径。
无论它位于何处,您的配置文件都应包含如下内容:
server {
listen 80;
listen 443 ssl;
server_name yourSite.com;
root "/path/to/yourSite";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /path/to/webserver/youSite.error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /path/to/yourSite.crt;
ssl_certificate_key /path/to/yourSite.key;
}
更改此文件后确保 sudo service nginx reload
或 sudo service nginx restart
(或相关的 apache 命令)。
sudo service nginx configtest
或 sudo nginx -t
将有助于调试配置文件。
今天我遇到了同样的问题,就像那样
我使用 curl http://localhost:8080
检查我的 tomcat 是否可以工作
错误Failed to connect to ::1: No route to host
终于解决了it.Obviously,是你的Apache问题tomcat。
所以你必须先检查你的日志。如果您发现您的端口已被使用,请找到该课程并将其杀死。然后重启你的 tomcat.
按端口查找课程:netstan -lnp | grep port
击杀课程:kill -9 ****
在对我的所有代码进行大量调试和测试后,我联系了该服务,我正尝试使用其 API。
他们是一家欧洲服务提供商,他们已将欧洲 IP 列入白名单。我们的生产服务器在美国,他们将我们的 IP 列入白名单后,一切正常。
找了一整天,发现问题出在iptables规则上。
在我的例子中,解决方案是按如下方式恢复 iptables 规则:
创建包含以下文本的文件:
*过滤器
:输入接受 [10128:1310789]
:转发接受[0:0]
:输出接受 [9631:1361545]
提交*
运行 命令:sudo iptables-restore < /path/to/your/previously/created/file
如果是 iptables 问题,这有望解决您的问题。
它对我适用于 apache (httpd)
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
所以我们正在 PHP 中构建一个 Web 应用程序,我们正在尝试向外部 API 发出请求。问题是我们收到卷曲错误:
cURL error 7: Failed to connect to external.api.com port 443: No route to host
现在介绍一些背景知识。
- 我们正在使用 Guzzle 发出请求。
- 我们在 Apache 上托管,它在 Linux 机器上 运行ning 并且我们也在使用 SSL。
- API 也在使用 SSL,因此错误消息中的端口 443。
- HTTP 请求包含用于身份验证的证书。
我已经设法在两个不同的开发环境中 运行 获得它,但在生产环境中却没有。我怀疑问题出在 Apache 的配置上,好像我们还没有让它可以向特定 IP 或端口发出请求。我不知道如何检查它。我读到我可能必须更改文件 /etc/network/interface,但我还没有找到任何关于在那里写什么的信息。
我也读过我必须 运行 $ netstat -rn
才能找到答案,但我不确定在那里看什么。
编辑:
没有任何参数和任何东西,甚至无法发出简单的 get 请求。 但是我可以向 https://google.com and https://facebook.com 提出请求。过几会再写。
netstat -aln | grep 443
将显示您的网络服务器是否正在侦听该端口。
根据您安装配置文件的网络服务器,站点将位于 /etc/nginx/sites-available/default
、/etc/nginx/sites-available/yourSite
、/etc/nginx/nginx.conf
或其他类似的 apache 路径。
无论它位于何处,您的配置文件都应包含如下内容:
server {
listen 80;
listen 443 ssl;
server_name yourSite.com;
root "/path/to/yourSite";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /path/to/webserver/youSite.error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /path/to/yourSite.crt;
ssl_certificate_key /path/to/yourSite.key;
}
更改此文件后确保 sudo service nginx reload
或 sudo service nginx restart
(或相关的 apache 命令)。
sudo service nginx configtest
或 sudo nginx -t
将有助于调试配置文件。
今天我遇到了同样的问题,就像那样
我使用 curl http://localhost:8080
检查我的 tomcat 是否可以工作
错误Failed to connect to ::1: No route to host
终于解决了it.Obviously,是你的Apache问题tomcat。 所以你必须先检查你的日志。如果您发现您的端口已被使用,请找到该课程并将其杀死。然后重启你的 tomcat.
按端口查找课程:netstan -lnp | grep port
击杀课程:kill -9 ****
在对我的所有代码进行大量调试和测试后,我联系了该服务,我正尝试使用其 API。
他们是一家欧洲服务提供商,他们已将欧洲 IP 列入白名单。我们的生产服务器在美国,他们将我们的 IP 列入白名单后,一切正常。
找了一整天,发现问题出在iptables规则上。 在我的例子中,解决方案是按如下方式恢复 iptables 规则:
创建包含以下文本的文件:
*过滤器
:输入接受 [10128:1310789]
:转发接受[0:0]
:输出接受 [9631:1361545]
提交*
运行 命令:
sudo iptables-restore < /path/to/your/previously/created/file
如果是 iptables 问题,这有望解决您的问题。
它对我适用于 apache (httpd)
iptables -I INPUT -p tcp --dport 80 -j ACCEPT