跳至主要内容

利用百度主动推送功能,实现每天固定时间更新百度最新收录页面

上一篇文章里面我们已经说到过百度自动推送更新的功能了,一篇我们来说说百度主动推送链接的功能和实现

功能和好处略过.....为什么呢?你不懂SEO那干嘛看这篇文章呢?对吧~~~~至于功能嘛.一般上官方看传送门!

准备工作:

1.网站服务器环境 (Ubuntu+lnmp+帝国CMS)这里是Sandy的服务器环境.没特别要求要一样

2.百度站长账号,注册传送门

3.有一定SEO和服务器操作知识

开始工作:

一 建立标签模版:

[!--empirenews.listtemp--]<!--list.var1-->[!--empirenews.listtemp--]
[!--titleurl--],

 

注意列表内容模板中的“,”号,文章中有着重说明。

注意新增加后的标签模板的ID数字,后面会用到。

二 自定义页面制作内容网址列表(TXT文本格式)

[ecmsinfo]'news',50,36,0,18,14,1[/ecmsinfo]

 

如上图'14'就是说明你刚才建立的模板ID

注1:生成的文件名后缀为txt:(文件名自己定,如baidu.txt),存放于网站根目录下;

注2:需要提交的更新网址条数(50)建议不要太多,可以自行修改,自定义标签ID(14)要更换成你自己帝国CMS网站后台对应的模板标签ID。

注3:浏览生成的baidu.txt文件,看看是否已经正确地生成了网址,并检查下网址内容是否为带有HTTP开始的绝对URL格式(如:http://ift.tt/2ClHxZO

如果txt文件中的网址不是带HTTP的绝对URL格式,进入网站参数修改调整。

三 添加PHP代码实现主动推送功能

在线版本:

<?php
$values = fopen('baidu.txt','r') or die("打开文件失败");
$value = fread($values,filesize('baidu.txt'));
$value = rtrim($value,",");
$urls =explode(',', $value);
$api = 'http://ift.tt/2BVrUVO';
$ch = curl_init();
$options =  array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\r\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
echo '<pre>' .htmlspecialchars(print_r($urls, true)) . '</pre>';
?>

注:以上代码只要替换3处,就可以匹配你的网站。

第一行和第二行的baudu.txt,换成你的帝国CMS网站后台的自定义页面文件名称即可,另外就是要注意这个PHP文件,最好也是上传到网站根目录,和baidu.txt并行,这样就不需要在代码中加入文件的路径,以免找不到网址文件而出错。

把$api=” http://ift.tt/2Cixrcu

上传PHP文件至网站服务器。如Sandy'Blog的URL地址是:http://ift.tt/2BV08J3 直接在浏览器中访问它。就会自动提交到百度去,然后你再次配合云监控类似的产品就可以实现更新了.这里就不说了!重点介绍是服务器执行推送.......

服务器版本

<?php
$values = fopen('/home/wwwroot/baidu.txt','r') or die("打开文件失败");
$value = fread($values,filesize('/home/wwwroot/baidu.txt'));
$value = rtrim($value,",");
$urls =explode(',', $value);
$api = 'http://ift.tt/2BVrUVO';
$ch = curl_init();
$options =  array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\r\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
echo '<pre>' .htmlspecialchars(print_r($urls, true)) . '</pre>';
?>

注:以上代码只要替换3处,就可以匹配你的网站。

第一行和第二行的baudu.txt,换成你服务器访问的目录路径即可,另外就是要注意这个PHP文件,最好也是上传到网站根目录,和baidu.txt并行,这样就不需要在代码中加入文件的路径,以免找不到网址文件而出错。

把$api=” http://ift.tt/2Cixrcu

上传PHP文件至网站服务器。记住上传的目录路径即可,下一步会使用到:

先看看你的服务器PHP路径是什么?

which php

然后进入crontab计划任务

crontab -e

加入每天早上8点提交给百度:

0 8 * * * /usr/bin/php /home/wwwroot/baidu.php

到此全部工作结束.......不管新站或者老站收录这个问题是个问题.所以好好对待吧!

这里提一下为什么Sandy比较推崇从服务器执行而且不是利用其它平台是执行最后一步自动化的主动推送功能呢?

首先服务器执行是自己可以掌控的.(-_-!控制狂魔,其实放云端也可以控制.只是总感觉不舒服)

其次可以少注册一个账户,少被广告骚扰.像阿里云的云监控有事没事给你发给广告.受不了.谁让你用了人家免费产品呢?

 

 

 

评论

此博客中的热门博文

阿里云通过Nginx中转Linode/digitalocean/AWS的V2ray协议,实现负载均衡

开篇文的废话.原因是Sandy做站服务器太多了,发现利用率不高,皮又痒了又想折腾了.v2ray是利器但是给人的感觉就是只能用一台服务器,官方也说不支持负载均衡,不会A服务器挂机,自动跳转到B服务器.这里就有点折磨人了.每个服务器挂了都要自己去改配置文件. 我们访问国外的服务器,如果没CN2的线路是非常慢的,起码不快!哈哈~现在VPS都便宜起码人手一个人有5台以上吧?这样的话我们就可以开整. 开整条件:国内VPS或者阿里云有CN2线路的机器最好是100MB-200MB的带宽的.保证你爽歪歪.但是Sandy在阿里云HK30MB下也测试了也可以达到30000KB以上,羡慕吧~我们可以开始了! 老规则工具先出: 没被gwf和谐的服务器1台(下文统称:主服务器) 国外服务器2台以上(下文统称:从服务器) nginx 1.9.5版本以上(推荐:lnmp1.4) v2ray croe 第一步: 在 主服务器 安装lnmp1.4,这里就不细说教程了.直接去 官方 看教程 安装完毕以后我们来升级Nginx让他支持stream模块 cd lnmp1.4 vi lnmp.conf 在Nginx_Modules_Options=‘’里面加入--with-stream Nginx_Modules_Options='--with-stream’ 然后执行升级命令 ./upgrade.sh nginx  第二步 修改nginx.conf文件 cd /usr/local/nginx/conf/nginx.conf 在 events { use epoll; worker_connections 51200; multi_accept on; } 下面加入 stream{ server{ listen 0.0.0.0:8080; proxy_pass v2ray_backend; proxy_timeout 10m; proxy_connect_timeout 5000ms; } upstream v2ray_backend{ server ...

利用haproxy来做V2RAY负载均衡

Sandy在之前有说过 阿里云通过Nginx中转Linode/digitalocean/AWS的V2ray协议,实现负载均衡 ,有些学童不想折腾nginx,那么我们可以用haproxy来折腾,不管是haproxy还是Nginx都可以在树莓派和局域网的PC机器折腾! 安装haproxy的教程就移步到-> haproxy安装教程 apt-get install haproxy 安装完毕,我们来修改haproxy的配置 vi /etc/haproxy/haproxy.cfg 里面内容全部删除,加入下面的内容 global ulimit-n 51200 log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid user haproxy group haproxy daemon defaults log global mode tcp retries 3 option dontlognull option redispatch #上游TCP服务器连接等待时间 timeout connect 5s timeout client 24h timeout server 24h #以下为Web管理页面设置,如不需要可以删除 listen admin_stats bind 0.0.0.0:8888 mode http log 127.0.0.1 local0 err stats refresh 30s stats uri /haproxy stats realm welcome login\ Haproxy stats auth admin:admin stats hide-version stat...

ssh over socks5:通过socks5 proxy来连接ssh服务器[转载]

最近因为不可描述的原因,我在aws soul的云主机访问不了,ssh、80、ss全部都被禁掉了。 80端口在chrome配置SwitchyOmega就可以了,但ssh不太好办,shell上配置http_proxy对ssh没什么用。 其实ssh自己就支持proxy。 注意这跟在ssh端口转发:远程和本地中介绍过使用ssh作为proxy的方法不同,ssh -D是为了用ssh做proxy,而不是通过proxy来连接ssh服务器。 TL;DR ssh -o ProxyCommand='nc -x 192.0.2.0:1080 %h %p' user@awshost 原理解析 $ man ssh_config ProxyCommand Specifies the command to use to connect to the server. The command string extends to the end of the line, and is executed using the user's shell ‘exec’ directive to avoid a lingering shell process. In the command string, any occurrence of ‘%h’ will be substituted by the host name to connect, ‘%p’ by the port, and ‘%r’ by the remote user name. The command can be basically anything, and should read from its standard input and write to its standard output. It should eventually connect an sshd(8) server running on some machine, or execute sshd -i somewhere. Host key management will be done using the HostName of the host being connected (defa...