卷曲错误:无主机路由

问题描述 投票:5回答:2

所以我们正在用PHP构建一个Web应用程序,我们正在尝试向外部API发出请求。问题是我们遇到卷曲错误:

cURL错误7:无法连接到external.api.com端口443:没有到主机的路由

现在有点背景。

  • 我们正在使用Guzzle提出请求。
  • 我们在Apache上运行,它运行在Linux机器上,我们也在使用SSL。
  • API也使用SSL,因此错误消息中的端口443。
  • HTTP请求包括用于身份验证的证书。

我设法让它在两个不同的开发环境中运行,但不在生产环境中运行。我怀疑问题出在Apache的配置中,好像我们没有让它可以向某些IP或端口发出请求。我不知道如何检查它。我已经读过我可能要更改文件/ etc / network / interface但我还没有找到任何关于在那里写什么的信息。

我也读过我必须运行$ netstat -rn的答案,但我不知道该怎么看。

编辑:

甚至无法在没有任何参数和任何内容的情况下制作简单的get请求但我可以向https://google.comhttps://facebook.com提出要求。会写几个更多。

php apache ssl curl guzzle
2个回答
2
投票

netstat -aln | grep 443将显示您的网络服务器是否正在侦听该端口。

根据您安装配置文件的Web服务器,该站点将位于/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 reloadsudo service nginx restart(或相对的apache命令)。

sudo service nginx configtestsudo nginx -t将帮助调试配置文件。


0
投票

在对我的所有代码进行了大量调试和测试之后,我联系了我正在尝试使用其API的服务。

他们是欧洲服务提供商,他们将欧洲IP列入白名单。我们的生产服务器在美国,在他们将我们的IP列入白名单后,一切正常。


-1
投票

今天我hava面对同样的问题,就像我用curl http://localhost:8080来检查我的tomcat可以工作与否

这是错误Failed to connect to ::1: No route to host

最后我解决了它。显然,这是你的Apache tomcat的问题。所以你必须先检查你的日志。如果您发现您的端口已被使用,请找到该路线并将其杀死。然后重启你的tomcat。

按端口找到航线:netstan -lnp | grep port杀人课程:kill -9 ****

© www.soinside.com 2019 - 2024. All rights reserved.