VPS侦探论坛

 找回密码
 注册
查看: 3654|回复: 7

curl获取页面失败,被目标网站告知未开启cookie,但是本地和..

[复制链接]
发表于 2019-8-7 12:01:33 | 显示全部楼层 |阅读模式

本地和另一个服务器(lamp)都能正常获取,file_get_contents都可以获取, 但是我现在的服务器安装的lnmp1.5获取不到, 代码是一样的.
看phpinfo发现
'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/conf.d' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-opcache' '--enable-intl' '--with-xsl'

'--with-curl'这项应该是 '--with-curl=/usr/local/curl'   但是lnmp安装后的不带path ,不知道是不是因为这个的原因
phpinfo 的curl
cURL support
enabled
cURL Information
7.61.1
Age
4
Features
AsynchDNS
Yes
CharConv
No
Debug
No
GSS-Negotiate
No
IDN
Yes
IPv6
Yes
krb4
No
Largefile
Yes
libz
Yes
NTLM
Yes
NTLMWB
Yes
SPNEGO
Yes
SSL
Yes
SSPI
No
TLS-SRP
No
Protocols
dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host
x86_64-redhat-linux-gnu
SSL Version
OpenSSL/1.0.2k
ZLib Version
1.2.8
libSSH Version
libssh2/1.4.2

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2019-8-7 13:23:04 | 显示全部楼层


php编译参数上是否采用另外编译的curl是由于架构和系统决定的,目前只有centos+arm才使用另外的curl
curl -V  看一下版本是否和php上的curl版本一样
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2019-8-7 14:04:47 | 显示全部楼层

licess 发表于 2019-8-7 13:23
php编译参数上是否采用另外编译的curl是由于架构和系统决定的,目前只有centos+arm才使用另外的curl
curl - ...

你好,我刚看了一下 curl版本是一样的;
服务器的curl命令也无法获取 curl url, 但是另一台服务器可以
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2019-8-7 17:18:50 | 显示全部楼层



坚果 发表于 2019-8-7 14:04
你好,我刚看了一下 curl版本是一样的;
服务器的curl命令也无法获取 curl url, 但是另一台服务器可以 ...

curl -v url 看一下
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2019-8-7 18:31:33 | 显示全部楼层

licess 发表于 2019-8-7 17:18
curl -v url 看一下

打不开的那个服务器返回403, 然后发现请求头不同. set_cookie的值也不同, 使用 curl --user-agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" -I  domain.com 返回也是403
下面是两个服务器的返回内容 (curl -v url)
* TCP_NODELAY set
* Connected to domain.com port 80 (#0)
> GET /es/get_data.php HTTP/1.1
> Host: domain.com
> User-Agent: curl/7.61.1
> Accept: */*

< HTTP/1.1 403 Forbidden
< Date: Wed, 07 Aug 2019 10:21:45 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
< CF-Chl-Bypass: 1
< Set-Cookie: __cfduid=d27fc3fa71f2972d77602132d758681001565173305; expires=Thu, 06-Aug-20 10:21:45 GMT; path=/; domain=.domain.com; HttpOnly
< Cache-Control: max-age=2
< Expires: Wed, 07 Aug 2019 10:21:47 GMT
< X-Frame-Options: SAMEORIGIN
< Server: cloudflare
< CF-RAY: 5028868a5ca95799-IAD

========= 分割线 ===========
* About to connect() to domain.com port 80 (#0)
*   Trying 104.31.82.83... connected
* Connected to domain.com  port 80 (#0)
> GET /es/get_data.php HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zl
> Host: domain.com
> Accept: */*

< HTTP/1.1 200 OK
< Date: Wed, 07 Aug 2019 09:56:22 GMT
< Content-Type: application/json;charset=utf-8
    < Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d9f5ed79be8ba4e0117b964eb22f94f4d1565171781; expires=Thu,
< X-Powered-By: PHP/5.4.16
        < P3P: CP="ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT D
< Set-Cookie: PHPSESSID=aj23uo6rcvkmamflrofhq9t363; path=/
< Set-Cookie: 2a0d2363701f23f8a75028924a3af643=MTYyLjE1OC43LjExNw%3D%3D; expires
< Expires: 0
< Last-Modified: Wed, 07 Aug 2019 09:56:22 GMT
< Cache-Control: pre-check=0, post-check=0, max-age=0
< Pragma: no-cache
< Server: cloudflare
< CF-RAY: 502861555b7020a0-KIX

军哥运维代购:http://shop63846532.taobao.com/

发表于 2019-8-8 10:35:51 | 显示全部楼层

是不是套了cdn,cdn上有设置过某些拦截规则
去掉cdn测试一下,或者时间不通过cdn 访问

curl -vH 'Host: 域名' http://源ip/es/get_data.php
看一下
 楼主| 发表于 2019-8-8 11:01:19 | 显示全部楼层

licess 发表于 2019-8-8 10:35
是不是套了cdn,cdn上有设置过某些拦截规则
去掉cdn测试一下,或者时间不通过cdn 访问

不好意思, 我不知道有没有设置cdn,刚搜了一会关于cdn的解释和如何关闭 没有找到相关的内容,或者是我没有看懂.
我这个服务器用的是亚马逊的,不知道是不是因为这个.
然后我运行命令: curl -vH 'Host: domain.com' http://ip/es/get_data.php 的返回的结果和之前是一样的
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2019-8-8 12:14:07 | 显示全部楼层

licess 发表于 2019-8-8 10:35
是不是套了cdn,cdn上有设置过某些拦截规则
去掉cdn测试一下,或者时间不通过cdn 访问

你好, 问题找到了, 目标网站禁止了亚马逊ip访问, 使用代理后访问成功了.
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-22 12:38 , Processed in 0.032775 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表