php 卷曲错误:没有到主机的路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38589862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Curl error : No route to host
提问by Mihkel Allorg
So we're building a web application in PHP and we're trying to make requests to an external API. Problem is that we're getting a curl error:
因此,我们正在用 PHP 构建一个 Web 应用程序,并尝试向外部 API 发出请求。问题是我们收到了 curl 错误:
cURL error 7: Failed to connect to external.api.com port 443: No route to host
cURL 错误 7:无法连接到 external.api.com 端口 443:没有到主机的路由
A little bit of background now.
现在有点背景。
- We're making requests using Guzzle.
- We're hosting on Apache, which is running on a Linux machine and we're also using SSL.
- The API is also using SSL, therefore the port 443 in error message.
- The HTTP requests include a certificate for authentication.
- 我们正在使用Guzzle发出请求。
- 我们托管在 Apache 上,Apache 运行在 Linux 机器上,我们也使用 SSL。
- API 也使用 SSL,因此错误消息中的端口为 443。
- HTTP 请求包括用于身份验证的证书。
I've managed to get it running on two different development environments but not on the production one. I suspect the problem is in the configuration of Apache, as if we haven't made it available to make requests to certain IP or port. I have no idea how to check it. I've read that I might have to change the file /etc/network/interface yet I haven't found any info on what to write there.
我设法让它在两种不同的开发环境中运行,但不能在生产环境中运行。我怀疑问题出在 Apache 的配置中,好像我们还没有使它可用于向某些 IP 或端口发出请求。我不知道如何检查它。我读过我可能需要更改文件 /etc/network/interface 但我还没有找到任何关于在那里写什么的信息。
I've also read I have to run $ netstat -rn
for answers yet I'm not sure what to look there.
我也读过我必须跑去$ netstat -rn
寻找答案,但我不确定在那里看什么。
EDIT:
编辑:
Can't even make a simple get request without any parameters and anything. Yet I can make requests to https://google.comand https://facebook.com. Will write more in a few.
甚至不能发出没有任何参数和任何东西的简单 get 请求。但是我可以向https://google.com和https://facebook.com提出请求。多写几篇。
采纳答案by Mihkel Allorg
After a lot of debugging and testing all of my code I contacted the service, whose API I was trying to consume.
在对我的所有代码进行大量调试和测试之后,我联系了该服务,我试图使用其 API。
They were an European service provider and they had whitelisted European IP's. Our production server was in the USA and after they whitelisted our IP, everything worked.
他们是一家欧洲服务提供商,并且已将欧洲 IP 列入白名单。我们的生产服务器在美国,在他们将我们的 IP 列入白名单后,一切正常。
回答by Lpgfmk
netstat -aln | grep 443
will show if your webserver is listening on that port.
netstat -aln | grep 443
将显示您的网络服务器是否正在侦听该端口。
Depending on which webserver you have installed your configuration file, for the site will be at /etc/nginx/sites-available/default
, /etc/nginx/sites-available/yourSite
, /etc/nginx/nginx.conf
or some other similar paths for apache.
根据该网络服务器安装在您的配置文件,该网站将在/etc/nginx/sites-available/default
,/etc/nginx/sites-available/yourSite
,/etc/nginx/nginx.conf
或一些其他类似的Apache路径。
Wherever it is located, your configuration file should contain something like the following:
无论它位于何处,您的配置文件都应包含如下内容:
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;
}
After changing this file make sure to sudo service nginx reload
or sudo service nginx restart
(or the relative apache command).
更改此文件后,请确保使用sudo service nginx reload
或sudo service nginx restart
(或相关的 apache 命令)。
sudo service nginx configtest
or sudo nginx -t
will help with debugging the config file.
sudo service nginx configtest
或sudo nginx -t
将有助于调试配置文件。
回答by CrownP
today I hava face up the same question, like that
I use curl http://localhost:8080
to check my tomcat can work or not
今天我遇到了同样的问题,就像我 curl http://localhost:8080
用来检查我的 tomcat 是否可以工作一样
And it's error Failed to connect to ::1: No route to host
这是错误 Failed to connect to ::1: No route to host
Finally I hava solve it.Obviously, it's the problem of your Apache tomcat. So you must check your logs firstly. If you found your port was used, find that course and kill it. Then restart your tomcat.
终于我解决了。很明显,这是你的Apache tomcat的问题。所以你必须首先检查你的日志。如果您发现您的端口已被使用,请找到该课程并将其杀死。然后重启你的tomcat。
find the course by port: netstan -lnp | grep port
kill course: kill -9 ****
通过端口查找课程: netstan -lnp | grep port
kill course: kill -9 ****