首页
统计
留言板
友链
关于
Search
1
三千书源
234,893 阅读
2
性价比还行的梯子
32,284 阅读
3
温暖的各类云盘资源交流世界——1OVE综合资源
24,852 阅读
4
Internet Download Manager(IDM) – 俄国大神制作
15,197 阅读
5
三千之图:随机图片调用接口
15,083 阅读
趣味技术
技术教程
干货资源
优质推荐
个人经验
清新文艺
特别文章
高质量文
登录
Search
标签搜索
合集
软件
宝塔
命令行
Python
脚本
勿埋我心
累计撰写
111
篇文章
累计收到
335
条评论
首页
栏目
趣味技术
技术教程
干货资源
优质推荐
个人经验
清新文艺
特别文章
高质量文
页面
统计
留言板
友链
关于
搜索到
54
篇与
的结果
2020-09-20
Typecho技巧:支持Emoji表情
引言安装完 typecho,发现并不能使用 Emoji 表情,评论里的 Emoji 表情,都会显示空白,看来不是 typecho 程序的问题,typecho 还是比较健壮的,于是苗头指向了数据库。建数据库的时候使用 utf-8,utf-8 是不支持 Emoji 表情的。要想数据库支持 Emoji 表情,就得使用 utf8mb4 编码来支持,于是我们需要修改已有数据库的编码格式,好消息是 utf8mb4 是 utf-8 的超集,完全兼容 utf-8,修改后,不会影响现有数据。修改数据表编码登录服务器的 MySQL 命令行或使用 phpAdmin,输入密码,进入 MySQL,切换到 typecho 的数据库。use typecho数据库名;执行以下 sql 语句,修改 typecho 数据库中表的编码格式为 utf8mb4。第一种:alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_options convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_general_ci; alter table typecho_users convert to character set utf8mb4 collate utf8mb4_general_ci;或者第二种(推荐):alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_options convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_unicode_ci; alter table typecho_users convert to character set utf8mb4 collate utf8mb4_unicode_ci;修改 config.inc.php 配置# 替换路径为自己的 config.inc.php 路径 vi /home/wwwroot/www.skyqian.com/config.inc.php按下 i 进入 vi 的编辑模式。修改 charset 的至为 utf8mb4。/** 定义数据库参数 */ $db = new Typecho_Db('Pdo_Mysql', 'typecho_'); $db->addServer(array ( ... 'charset' => 'utf8mb4', # 修改编码为 utf8mb4 ... ), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);按下 :,输入 wq 保存文件。这样就成功为 typecho 开启的 Emoji 支持。输入一个表情试试:
2020年09月20日
2,718 阅读
0 评论
8 点赞
2020-09-13
Nginx/Apache之伪静态设置
一、什么是伪静态伪静态即是网站本身是动态网页如.php、.asp、.aspx等格式动态网页有时这类动态网页还跟"?"加参数来读取数据库内不同资料,伪静态就是做url重写操作(即rewrite)。很典型的案例即是discuz论坛系统,后台就有一个设置伪静态功能,开启伪静态后,动态网页即被转换重写成静态网页类型页面,通过浏览器访问地址和真的静态页面没区别。但是记住:做伪静态的前提就是服务器要支持伪静态重写URL Rewrite功能。考虑搜索引擎优化(即SEO),将动态网页通过服务器处理成静态页面,如www.kevin.com/jk/fd.php?=12这样的动态网页处理成www.kevin.com/jk-fd-12.html这样格式静态页面,常见的论坛帖子页面,都是经过伪静态处理成静态页面格式html页面。由于网站所用的程序语言不易被发现,经过重写来伪静态来将动态网页的程序后缀变为html的静态页面格式。伪静态是一种可以把文件后缀改成任何可能的一种方法,比如如果想把php文件伪静态成html文件,这种配置相当简单的,后面会提到相应配置。二、真静态、伪静态优点和缺点真静态(html)优点减少服务器对数据响应的负荷;加载不用调动数据库,响应速度快。真静态缺点维护不方便,每次都要手动生成;空间占用比较大,容易造成磁盘压力;生成的文件多,服务器对html文件的响应负担也较重。伪静态(url重写)优点可以方便的实现对化化引擎的优化,并且比生成静态更加方便;占空间比较小;首页每天都自动变化,不用维护。网站首页一般都有热点排行之类的,你可以设为,24小时排行,一周排行,再加上最新文章,最新点评等。这样首页天天是有变化的;便于广告的轮显。比如:你可以把 art1234.aspx,这个虚成n个页,如art_1234.aspx,news_1234.aspx,top_1234.aspx,在不同的页面放 不同的广告。总之是动态的,就可以随意动。伪静态缺点如果流量稍大一些使用伪静态就出现CPU使用超负荷,因为伪静态是用正则判断而不是真实地址,分辨到底显示哪个页面的责任也由直接指定转由CPU来判断了,所以CPU占有量的上升,确实是伪静态最大的弊病;伪静态效率不如生成html的,因为它不是真正意义上的静态页,所以每次请求都是要去读取数据库的信息(这个可以用缓存技术来补偿一下)。三、真静态、伪静态原理与实现方案1. 伪静态伪静态是相对于真静态而言的,就是把一些asp,php等结尾url通过apche或nginx的重写规则,变成以html一类的静态页面形式。伪静态不是真正的静态,它和动态地址一样要读取数据库。伪静态最主要的作用就是利于seo,百度spider(百度蜘蛛)喜欢抓取静态页面,可容易使百度spider陷入死循环;并发量高的时候会加大服务器的压力,所以用的时候要注意。伪静态就是利用apche,nginx重写规则,对url地址重写实现的!伪静态实现原理:Apache伪静态前提是要打开apache的重写模块 (即打开"LoadModule rewrite_module modules/mod_rewrite.so"这一行);Nginx默认就支持伪静态;伪静态有两种配置方式在配置虚拟主机的时候设置;在web根目录下创建一个.htaccess文件,在这个文件里面配置;2. 真静态在网站设计中,纯粹HTML(标准通用标记语言下的一个应用)格式的网页通常被称为"静态网页",静态网页是标准的HTML文件,它的文件扩展名是.htm、.html,可以包含文本、图像、声音、FLASH动画、客户端脚本和ActiveX控件及JAVA小程序等。静态网页是网站建设的基础,早期的网站一般都是由静态网页制作的。静态网页是相对于动态网页而言,是指没有后台数据库、不含程序和不可交互的网页。静态网页相对更新起来比较麻烦,适用于一般更新较少的展示型网站。容易误解的是静态页面都是htm这类页面,实际上静态也不是完全静态,它也可以出现各种动态的效果,如GIF格式的动画、FLASH、滚动字幕等。大型web项目优化中经常会考虑到使用真静态,这样在访问量大的时候,可以减少cpu的压力,但是会生成大量的文件占用网站的磁盘空间,可以写个php的脚本或用linux的计划任务进行删除。在用真静态的时候有的时候需要用到局部的动态化。真静态实现方法利用PHP模板生成静态页面;使用PHP文件读写功能生成静态页面;使用PHP输出控制函数缓存机制生成静态页面;使用nosql从内存中读取内容(其实这个已经不算静态化了而是缓存);memcached是键值一一对应,key默认最大不能超过128个字节,value默认大小是1M,因此1M大小满足大多数网页大小的存储。真静态和伪静态的区别是不是一个真正静态页面;有没有和数据库或后台程序进行交互;它们的应用场景和解决的问题不同;用javascript:alert(document.lastModified)来判断是真静态还是伪静态;真静态在apache和nginx上的区别与否真静态在nginx上的运行速度比apache运行速度快;nginx处理静态文件对于apache来说消耗的内存少;伪静态在apache和nginx上的区别与否本质上没有区别,两者都是根据正则匹配对应的url的重写。但是apache和nginx上的伪静态规则还是有点不同,在配置的时候要注意;apache处理伪静态比nginx更有优势;3. 简单小示例跳转需求: 访问http://www.kevin.com/p/123456.html 跳转成 http://a.aa.com/p/123456 配置如下: rewrite ^/p/(\d+).html http://www.kevin.com/p/$1 last; 解释说明: \d是数字的意思 +是最少一个{1,} 1到无穷大{1,3} 这样是1-3位数。四、Nginx伪静态配置和常用Rewrite伪静态规则1. nginx防盗链location ~* \.(gif|jpg|png)$ { valid_referers none blocked http://kevin.com:81; #允许访问的来源,即所有来自http://kevin.com:81的gif|jpg|png结尾的文件 if ($invalid_referer) { rewrite ^/ http://kevin.com:81/c2_.html; #return 403; } }2. 伪静态重写location / { rewrite c(\d+)_(.*).html /index.php?c=user&m=index&id=$1&title=$2 last; root /usr/share/nginx/html/sta; index index.html index.htm index.php; }对于生成大量的大量html文件,推荐使用rsync工具进行批量删除1. 建立一个空目录 ## mkdir -p /root/kevin/tmp/ 2. 确认需要清空的目标目录(即需要删除的大量html文件所在的目录),比如/root/kevin/tmp1/ 3)使用rsync同步删除(注意目录后面的“/”),整体效率会快一个数量级的样子。 ## rsync --delete-before -a -H /root/kevin/tmp/ /root/kevin/tmp1/ 选项说明: –delete-before 接收者在传输之前进行删除操作 –progress 在传输时显示传输过程 -a 归档模式,表示以递归方式传输文件,并保持所有文件属性 -H 保持硬连接的文件 -v 详细输出模式 -stats 给出某些文件的传输状态 如下操作可以把某个超大文件删掉,比如删除/mnt/ops/web.html文件 1)建立空文件/mnt/ops/html.txt 2)## rsync --delete-before -a -H -v --progress --stats /mnt/ops/html.txt /mnt/ops/web.html 3)这样置为空后就可以快速删掉 原理: 把文件系统的目录与书籍的目录做类比,rm删除内容时,将目录的每一个条目逐个删除(unlink),需要循环重复操作很多次; rsync删除内容时,建立好新的空目录,替换掉老目录,基本没开销。 测试大文件删除 1)生成文件 ## for i in $(seq 1 500000); do echo test >>/opt/test/$i.txt; done 测试结果: 10万文件rm删除第一次11s左右,第二次9s左右;rsync测试两次9s左右 50万文件rm删除报错;rsync测试两次一个5分左右,一个4分左右 rm删除命令 ## time rm -f /opt/test/*.txt rsync命令删除 ## mkdir /opt/test1 ## rsync --delete-before -a -H -v --progress --stats /opt/test1/ /opt/test/nginx php thinkphp5 伪静态配置示例server { listen 80; server_name 127.0.0.1 localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { if (!-e $request_filename) { #一级目录 #rewrite ^/(.*)$ /index.php?s=$1 last; #二级目录 rewrite ^/TWcloud/public/(.*)$ /TWcloud/public/index.php?s=$1 last; break; } root /Applications/MxSrvs/www; index index.html index.htm index.php; } location ~ \.php { #去掉$ root /Applications/MxSrvs/www; fastcgi_pass 127.0.0.1:10080; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; #增加这一句 fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }thinkphp 5.0的nginx伪静态规则配置示例 [踩过坑点,经测试实现]server { listen 80; server_name www.kevin.com; root /data/www/web; location / { index index.html index.htm index.php default.php; #重点就是加入下面这个if if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ .php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.html; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } }先来看一个nginx伪静态配置示例场景一: 把 http://www.abc.com/index.php/front/index/index 重写成 http://www.abc.com/a.html 场景二: 把下面带参数的第1、2个url解析成第3个url 1.http://www.abc.com/index.php/front/index/parse/name/yangxignyi/age/18 2.http://www.abc.com/index.php/front/index/parse?name=yangxignyi&age=18 3.http://www.abc.com/parse-yangxignyi-18.html 服务器配置文件: server{ listen 80; server_name www.abc.com; root /data/www/web; location / { index index.php index.htm /public/index.html; autoindex off; include abc.conf; #rewrite a.html /index.php/front/index/index last; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } 伪静态配置文件可以直接写在location /{} 里面的,不推荐这样做!! 建议新增加个rewrite.conf文件,写伪静态文件会好点,include 引入进来就行了,这样可以在rewrite.conf里面写n多配置 location / { index index.php index.htm /public/index.html; autoindex off; include rewrite.conf; #rewrite a.html /index.php/front/index/index last; } #rewrite.conf (这个文件自己创建就行了,文件内容写规则),伪静态配置如下: #场景一的规则 #http://www.abc.com/index.php/front/index/index rewrite a.html /index.php/front/index/index last; #场景二的规则 #1.http://www.abc.com/index.php/front/index/parse/name/yangxignyi/age/18 #2.http://www.abc.com/index.php/front/index/parse?name=yangxignyi&age=18 #3.http://www.abc.com/parse-yangxingyi-18.html rewrite parse-(\w+)-(\d+).html /index.php/front/index/parse/name/$1/age/$2 last; 如上配置中的\w是数字字母下划线的意思,\d是数字的意思 +是最少一个{1,} 1到无穷大{1,3} 这样是1-3位数。3. nginx伪静态的Rewrite重写的正则匹配规则正则表达式匹配 : ~ 为区分大小写的匹配 ~* 不区分大小写的匹配(匹配firefox的正则同时匹配FireFox) !~ 区分大小写的不匹配 !~* 不区分大小写的不匹配 \ 将后面接着的字符标记为一个特殊字符或者一个原义字符或一个向后引用 . 匹配除换行符以外的任意字符,即匹配除"\n"之外的所有单个字符 \w 匹配字母或数字或下划线或汉字 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配字符串的开始,即匹配输入字符串的起始位置 $ 匹配字符串的结束,即匹配输入字符串的结束位置 * 重复零次或更多次,即匹配前面的字符零次或者多次 + 重复一次或更多次,即匹配前面字符串一次或者多次 ? 重复零次或一次,即匹配前面字符串的零次或者一次 {n} 重复n次 {n,} 重复n次或更多次 {n,m} 重复n到m次 *? 重复任意次,但尽可能少重复 +? 重复1次或更多次,但尽可能少重复 ?? 重复0次或1次,但尽可能少重复 {n,m}? 重复n到m次,但尽可能少重复 {n,}? 重复n次以上,但尽可能少重复 \W 匹配任意不是字母,数字,下划线,汉字的字符 \S 匹配任意不是空白符的字符 \D 匹配任意非数字的字符 \B 匹配不是单词开头或结束的位置 [^x] 匹配除了x以外的任意字符 文件及目录匹配,其中: -f和!-f 用来判断是否存在文件 -d和!-d 用来判断是否存在目录 -e和!-e 用来判断是否存在文件或目录 -x和!-x 用来判断文件是否可执行 flag标记有: last 相当于Apache里的[L]标记,表示完成rewrite。即本条规则匹配完成后继续向下匹配新的location URI规则 break 终止匹配, 不再匹配后面的规则。即本条规则匹配完成后终止,不在匹配任何规则 redirect 返回302临时重定向 地址栏会显示跳转后的地址 permanent 返回301永久重定向 地址栏会显示跳转后的地址 $args 此变量与请求行中的参数相等 $content_length 等于请求行的“Content_Length”的值。 $content_type 等同与请求头部的”Content_Type”的值 $document_root 等同于当前请求的root指令指定的值 $document_uri 与 $uri 一样 $host 与请求头部中“Host”行指定的值或是request到达的server的名字(没有Host行)一样 $limit_rate 允许限制的连接速率 $request_method 等同于request的method,通常是“GET”或“POST” $remote_addr 客户端ip $remote_port 客户端port $remote_user 等同于用户名,由ngx_http_auth_basic_module认证 $request_filename 当前请求的文件的路径名,由root或alias和URI request组合而成 $request_body_file $request_uri 含有参数的完整的初始URI $query_string 与 $args一样 $server_protocol 等同于request的协议,使用“HTTP/1.0”或“HTTP/1.1” $server_addr request 到达的server的ip,一般获得此变量的值的目的是进行系统调用。为了避免系统调用,有必要在listen指令中指明ip,并使用bind参数。 $server_name 请求到达的服务器名 $server_port 请求到达的服务器的端口号 $uri 等同于当前request中的URI,可不同于初始值,例如内部重定向时或使用index总的来说,location中的rewrite,不写last和break,那么流程就是依次执行这些rewriterewrite btrak:表示url重写后,直接使用当前资源,不再执行location里余下的语句,完成本次请求后,地址url不变。rewrite last:表示url重写后,马上发起一个新的请求,再次进入server块,重试location匹配,超过10次匹配不到就报500错误,地址栏url不变。rewrite redirect:表示返回302临时重定向,地址栏显示重定向后的url,爬虫不会重写url,因为是临时。rewrite permanent:表示返回301永久重定向,地址栏显示重定向后的url,爬虫重写url。rewrite重写跳转的应用场景调整用户浏览的URL,看起来规范为了让搜索引擎收录网站内容,让用户体验更好网站更换新域名后根据特殊的变量、目录、客户端信息进行跳转常用301跳转的rewrite重写示例1)301跳转 之前常用起别名的方式做到了不同地址访问同一个虚拟主机的资源,现在可以用一个更好的方式做到这一点,那就是跳转的方法来实现。 比如www.kevin.com虚拟主机为例子,修改配置文件如下: server { ## 添加个server区块做跳转 listen 80; server_name kevin.com; rewrite ^/(.*) http://www.kevin.com/$1 permanent; } server { listen 80; server_name www.kevin.com; location / { root html/brian; index index.html index.htm; } access_log logs/brian.log main gzip buffer=128k flush=5s; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } 这样,当访问域名http://kevin.com时,就301永久跳转到http://www.kevin.com域名了,跳转后的地址是http://www.kevin.com 2)域名跳转: 不仅可以做相同虚拟主机的资源域名跳转,也能做不同虚拟主机的域名跳转,下面就跳转下当访问kevin.com域名的时候跳转到www.baidu.com的页面: 修改配置文件: server { #添加个server区块做跳转 listen 80; server_name kevin.com; rewrite ^/(.*) http://www.kevin.com/$1 permanent; } server { listen 80; server_name www.kevin.com; location / { root html/brian; index index.html index.htm; } access_log logs/brian.log main gzip buffer=128k flush=5s; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } 这样,当访问http://kevin.com时,就跳转到了http://www.baidu.com,跳转后的地址是http://www.baidu.com4. nginx伪静态常用配置示例nginx里使用伪静态是直接在nginx.conf 中写规则的,并不需要像apache要开启写模块(mod_rewrite)才能进行伪静态。 nginx只需要打开nginx.conf配置文件,在server里面写需要的规则即可。 1)配置案例1 server { listen 80; server_name www.kevin.com; index index.html index.htm index.php; rewrite ^/wangla.html$ http://www.baidu.com/ permanent; rewrite ^/(\d+).html$ http://www.qq.com/ permanent; rewrite ^/(\w+).html$ http://wd.gyyx.cn/index_wd_v5.htm permanent; } 以上添加了几条重写规则 访问www.kevin.com/wangla.html跳转到百度 访问www.kevin.com/纯数字至少一个数字.html跳转到QQ官网 访问www.kevin.com/匹配字母或数字或下划线组合.html 跳转到问道官网。 2)配置案例2 server { listen 80; server_name bbs.jb51.net; index index.html index.htm index.php; root /home/www/bbs; error_page 404 /404.htm; #配置404错误页面 location ~ .*.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } #下面就是伪静态了 location /{ rewrite ^(.*)/equip(d+).html$ $1/index.php?m=content&c=index&a=lists&catid=$2 last; } access_log access_log off; } 然后重启nginx服务器伪静态就生效了,这种维护起来很是不方便我们可以把它写在外部文件如bbs_nginx.conf中 在/home/www/bbs目录下创建bbs_nginx.conf文件并写入以下代码: location /{ rewrite ^(.*)/equip(d+).html$ $1/index.php?m=content&c=index&a=lists&catid=$2 last; } 然后在上面的代码后面加上如下代码: include /home/www/bbs/bbs_nginx.conf; 这样网站根目录中的bbs_nginx.conf伪静态规则,即可实现单独管理。 下面是一个实例: 在使用.htaccess文件的目录下新建一个.htaccess文件,如下面一个Discuz论坛目录: ## vim /var/www/html/jb51/bbs/.htaccess rewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last; rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last; rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last; rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last; rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last; rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last; 接着修改nginx配置文件: ## vim /etc/nginx/nginx.conf 在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件: include /var/www/html/jb51/bbs/.htaccess; 最后重新加载nginx配置文件: ## /etc/init.d/nginx reload 3)下面是一些rewrite配置集锦,供运维参考: ======================================================================================= rewrite "^/(.{6})(\d{3})(.+)/php/" http://www.kevin.com/qq$2.apk break; 中间用到了{6}指前面的字符得复6次 结合PHP的例子 if (!-d $request_filename) { rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last; rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&controller=$1 last; break; 多目录转成参数。 abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2 配置如下: if ($host ~* (.*)\.domain\.com) { set $sub_name $1; rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last; } 目录对换 /123456/xxxx -> /xxxx?id=123456 配置如下: rewrite ^/(\d+)/(.+)/ /$2?id=$1 last; 例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下: if ($http_user_agent ~ MSIE) { rewrite ^(.*)$ /nginx-ie/$1 break; } 目录自动加"/" if (-d $request_filename){ rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; } 禁止htaccess location ~/\.ht { deny all; } 禁止多个目录 location ~ ^/(cron|templates)/ { deny all; break; } 禁止以/data开头的文件 可以禁止/data/下多级目录下.log.txt等请求; location ~ ^/data { deny all; } 禁止单个目录 不能禁止.log.txt能请求 location /searchword/cron/ { deny all; } 禁止单个文件 location ~ /data/sql/data.sql { deny all; } 给favicon.ico和robots.txt设置过期时间; 这里为favicon.ico为99 天,robots.txt为7天并不记录404错误日志 location ~(favicon.ico) { log_not_found off; expires 99d; break; } location ~(robots.txt) { log_not_found off; expires 7d; break; } 设定某个文件的过期时间;这里为600秒,并不记录访问日志 location ^~ /html/scripts/loadhead_1.js { access_log off; root /opt/lampp/htdocs/web; expires 600; break; } 文件反盗链并设置过期时间 这里的return 412 为自定义的http状态码,默认为403,方便找出正确的盗链的请求 "rewrite ^/ http://leech.c1gstudio.com/leech.gif;"显示一张防盗链图片 "access_log off;"不记录访问日志,减轻压力 "expires 3d"所有文件3天的浏览器缓存 location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ { valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194; if ($invalid_referer) { rewrite ^/ http://leech.c1gstudio.com/leech.gif; return 412; break; } access_log off; root /opt/lampp/htdocs/web; expires 3d; break; } 只充许固定ip访问网站,并加上密码 root /opt/htdocs/www; allow 218.197.16.14; allow 22.133.11.22; allow 21.112.69.14; deny all; auth_basic "C1G_ADMIN"; auth_basic_user_file htpasswd; 将多级目录下的文件转成一个文件,增强seo效果 /job-123-456-789.html 指向/job/123/456/789.html 配置如下: rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /job/$1/$2/jobshow_$3.html last; -------------------------------------------------------------------------------- 将根目录下某个文件夹指向2级目录 如/shanghaijob/ 指向 /area/shanghai/ 如果你将last改成permanent,那么浏览器地址栏显是 /location/shanghai/ 配置如下: rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last; 上面例子有个问题是访问/shanghai 时将不会匹配 rewrite ^/([0-9a-z]+)job$ /area/$1/ last; rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last; 这样/shanghai 也可以访问了,但页面中的相对链接无法使用, 如./list_1.html真实地址是/area /shanghia/list_1.html会变成/list_1.html,导至无法访问。 那加上自动跳转也是不行的! (-d $request_filename)它有个条件是必需为真实目录,而我的rewrite不是的,所以没有效果。 if (-d $request_filename){ rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; } 知道原因后就好办了,手动跳转吧 rewrite ^/([0-9a-z]+)job$ /$1job/ permanent; rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last; -------------------------------------------------------------------------------- 文件和目录不存在的时候重定向: if (!-e $request_filename) { proxy_pass http://127.0.0.1/; } 域名跳转 server { listen 80; server_name jump.c1gstudio.com; index index.html index.htm index.php; root /opt/lampp/htdocs/www; rewrite ^/ http://www.c1gstudio.com/; access_log off; } 多域名转向 server_name http://www.c1gstudio.com/ http://www.c1gstudio.net/; index index.html index.htm index.php; root /opt/lampp/htdocs; if ($host ~ "c1gstudio\.net") { rewrite ^(.*) http://www.c1gstudio.com$1/ permanent; } 三级域名跳转 if ($http_host ~* "^(.*)\.i\.c1gstudio\.com$") { rewrite ^(.*) http://top.yingjiesheng.com$1/; break; } 域名镜向 server { listen 80; server_name mirror.c1gstudio.com; index index.html index.htm index.php; root /opt/lampp/htdocs/www; rewrite ^/(.*) http://www.c1gstudio.com/$1 last; access_log off; } 某个子目录作镜向 location ^~ /zhaopinhui { rewrite ^.+ http://zph.c1gstudio.com/ last; break; } discuz ucenter home (uchome) rewrite伪静态配置 rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last; rewrite ^/(space|network)\.html$ /$1.php last; rewrite ^/([0-9]+)$ /space.php?uid=$1 last; discuz 7 rewrite伪静态配置 rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last; rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last; rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\=$4&page=$3 last; rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last; rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last; rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last; 给discuz某版块单独配置域名 server_name bbs.c1gstudio.com news.c1gstudio.com; location = / { if ($http_host ~ news\.c1gstudio.com$) { rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last; break; } } discuz ucenter 头像 rewrite 优化 location ^~ /ucenter { location ~ .*\.php?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location /ucenter/data/avatar { log_not_found off; access_log off; location ~ /(.*)_big\.jpg$ { error_page 404 /ucenter/images/noavatar_big.gif; } location ~ /(.*)_middle\.jpg$ { error_page 404 /ucenter/images/noavatar_middle.gif; } location ~ /(.*)_small\.jpg$ { error_page 404 /ucenter/images/noavatar_small.gif; } expires 300; break; } } jspace rewrite伪静态配置 location ~ .*\.php?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~* ^/index.php/ { rewrite ^/index.php/(.*) /index.php?$1 break; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; }Nginx伪静态配置示例2公司域名bo.kevin.com下有多个子项目目录结构大致是bo.kevin.com/own/xys |bo.kevin.com/2017/abc |bo.kevin.com/2018/def有二级也有三级目录, 应开发需求某项目访问地址是:bo.kevin.com/own/xys/index.php/admin/login 需要把index.php隐藏为bo.kevin.com/own/xys/index/admin/login进行访问。 设定以下三种场景: 场景一 将 http://www.abc.com/index.php/front/index/index 重写成 http://www.abc.com/a.html 场景二 将 http://www.abc.com/index.php/front/index/parse?name=itboy&age=18 重写成 http://www.abc.com/parse-itboy-18.html 场景三(同一域名下,需要匹配随时新增的二三级目录,并隐藏index.php的.php后缀) 将 http://bo.kevin.com/own/xys/index.php/admin/login 以及 http://bo.kevin.com/2018/gdhp/index.php/login 重写成 http://bo.kevin.com/own/xys/index/admin/login 以及 http://bo.kevin.com/2018/gdhp 建议在nginx/conf目录下新建rewrite.conf配置文件中编写伪静态规则,写完后在域名.conf文件中插入rewrite.conf文件即可(用include rewrite.conf插入)。 nginx配置文件如下: server { listen 80; server_name bo.kevin.com; index index.html index.php index.htm index.php default.html default.htm default.php; root /var/www/apps/bo.kevin.com; include rewrite.conf; include none.conf; error_page 502 /502.html; include enable-php-pathinfo.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /var/www/wwwlogs/bo.kevin.com.log; error_log /var/www/wwwlogs/error.bo.kevin.com.log; } rewrite.conf文件内容如下: location /{ #场景一 #http://www.abc.com/index.php/front/index/index 变成 http://www.abc.com/a.html rewrite a.html /index.php/front/index/index last; #场景二 #http://www.abc.com/index.php/front/index/parse?name=itboy&age=18 变成 http://www.abc.com/parse-itboy-18.html rewrite parse-(\w+)-(\d+).html /index.php/front/index/parse/name/$1/age/$2 last; #场景三 #http://bo.kevin.com/own/xys/index.php/admin/login 以及 http://bo.kevin.com/2018/gdhp/index.php/login #变成 http://bo.kevin.com/own/xys/index/admin/login 以及 http://bo.kevin.com/2018/gdhp/index/login rewrite ^/(\w+)/(\w+)/(.*)$ /$1/$2/index.php?s=$3 last; #针对own目录伪静态规则,$1对应(\w+)部分,$2对应第二个(\w+)部分,$3对应(.*)部分,$代表直至最后 rewrite ^/(\d+)/(\w+)/(.*)$ /$1/$2/index.php?s=$3 last; #针对后期的2018下的子项目伪静态规则 } 说明: 其实都是很简单的对号入座原理而已,拿场景二来说明,第一个正则(\w+)对应的就是$1,第二个正则(\d+)对应的就是$2, 另外,\w是数字字母下划线的意思,\d是数字的意思 +是最少一个{1,} 1到无穷大{1,3} 这样是1-3位数。Nginx上支持.htaccess伪静态的配置示例## vim /usr/local/nginx/conf/vhost/web.conf ........ include /var/www/web/.htaccess ## vim /var/www/web/.htaccess rewrite ^/show-([0-9]+)-([0-9]+)\.html$ /index.php?action=show&id=$1&page=$2; rewrite ^/category-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&cid=$1&page=$2; rewrite ^/archives-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&setdate=$1&page=$2; rewrite ^/(archives|search|reg|login|index|links)\.html$ /index.php?action=$1; rewrite ^/(comments|tagslist|trackbacks|index)-([0-9]+)\.html$ /index.php?action=$1&page=$2; if ($host != 'www.shibo.com' ) { rewrite ^/(.*)$ http://www.shibo.com/$1 permanent; } error_page 404 http://www.shibo.com/; ## /usr/local/nginx/sbin/nginx -s reloadnginx伪静态配置示例3 [去除框架的Index.php]在nginx.conf中Location/{}中加上下面这个if判断就可以了: location /{ if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } =============================================================================== 如下面一个配置 if (!-e $request_filename) { rewrite ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)\.html /index.php?m=$1&c=$2&a=$3&$4=$5&$6=$7 last; break; }Nginx 伪静态配置示例4访问 http://www.kevin.com/sort/15.html -> http://www.kevin.com/1.php?id=15 location / { root /usr/share/nginx/html/1; index index.html; rewrite /sort/(.*)\.html /1.php?id=$1 last; } ================================================================================ 再如下面一个配置 server { listen 80 default_server; server_name _; location / { root /usr/share/nginx/html; index index.html index.htm; rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$2&id=$3; } } 策略:RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$2&id=$3 请求路径:http://www.abc.com/list-123-456.html 以上策略分成两段: 第一段是使用正则表达式去匹配请求访问的路径,第二段是将匹配后的参数转化为真实访问的路径。 策略执行时:^(.*)list-([0-9]+)-([0-9]+)\.html$ 与 /list-123-456.html 这个字符串进行匹配: ^和$字符分别代表了匹配输入字符串的开始和结束; ()中的匹配到的内容会被按顺序分配到变量$1 $2 $3中; .*匹配任意字符串,且长度从0个到多个,故$1值为/; [0-9]+匹配字符0-9,长度1个到多个,故$2和$3分别是123和456; 所以最后真实访问的动态地址为 /list.php?page=123&id=456 ================================================================================ 再如下面一个配置 1)/a/b?c=d => index.php?_a=a&_m=b&c=d 2)/xxx/detail-yyy.html => index.php?_a=xxx&_m=detail&id=yyy 配置如下: server { listen 80; server_name my.xh5.com; location / { root /mnt/hgfs/web/my.xueh5.com/src/; index index.html index.htm index.php; if ($args ~ "^(.*)$"){ set $rule_0 1$rule_0; set $bref_1 $1; } if ($rule_0 = "1"){ rewrite ^([0-9a-zA-Z]*)/detail-([0-9]*)\.html$ /index.php?_a=$1&_m=detail&id=$2&$bref_1 last; rewrite ^/([0-9a-zA-Z]*)/([0-9a-zA-Z.]*)$ /index.php?_a=$1&_m=$2&$bref_1 last; rewrite ^/([0-9a-zA-Z]+)$ /index.php?_a=$1&_m=index&$bref_1 last; rewrite ^/$ /index.php?_a=index&_m=index&$bref_1 last; } } location ~ \.php$ { root /mnt/hgfs/web/my.xueh5.com/src/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }5. Nginx伪静态常用规则配置总结1)WordPress伪静态 if (-f $request_filename/index.html){ rewrite (.) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } 2)PHPCMS伪静态 rewrite ^/caipu-([0-9]+)-([0-9]+)-([0-9]+).html /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last; rewrite ^/content-([0-9]+)-([0-9]+)-([0-9]+).html /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last; rewrite ^/list-([0-9]+)-([0-9]+).html /index.php?m=content&c=index&a=lists&catid=$1&page=$2 last; rewrite ^/tag-([^.])-([0-9]+)-([0-9]+).html /index.php?m=content&c=tag&catid=$2&tag=$1&page=$3 last; rewrite ^/comment-([0-9]+)-([0-9]+)-([0-9]+).html /index.php?m=comment&c=index&a=init&commentid=content_$1-$2-$3 last; rewrite ^/([^.]).html /index.php?m=member&c=index&a=$1 last; 3)DEDECMS伪静态 rewrite "^/index.html$" /index.php last; rewrite "^/list-([0-9]+).html$" /plus/list.php?tid=$1 last; rewrite "^/list-([0-9]+)-([0-9]+)-([0-9]+).html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last; rewrite "^/view-([0-9]+)-1.html$" /plus/view.php?arcID=$1 last; rewrite "^/view-([0-9]+)-([0-9]+).html$" /plus/view.php?aid=$1&pageno=$2 last; rewrite "^/tags.html$" /tags.php last; rewrite "^/tag-([0-9]+)-([0-9]+).html$" /tags.php?/$1/$2/ last; 4)Discuz7伪静态 rewrite ^/archiver/((fid|tid)-[\w-]+.html)$ /archiver/index.php?$1 last; rewrite ^/forum-([0-9]+)-([0-9]+).html$ /forumdisplay.php?fid=$1&page=$2 last; rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last; rewrite ^/space-(username|uid)-(.+).html$ /space.php?$1=$2 last; rewrite ^/tag-(.+).html$ /tag.php?name=$1 last; 5)DiscuzX伪静态 rewrite ^([^.])/topic-(.+).html$ $1/portal.php?mod=topic&topic=$2 last; rewrite ^([^.])/article-([0-9]+)-([0-9]+).html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^.])/forum-(\w+)-([0-9]+).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^.])/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^.])/group-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^.])/space-(username|uid)-(.+).html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^.]*)/([a-z]+)-(.+).html$ $1/$2.php?rewrite=$3 last; if (!-e $request_filename) { return 404; } 6)ECSHOP伪静态 if (!-e $request_filename) { rewrite "^/index.html" /index.php last; rewrite "^/category$" /index.php last; rewrite "^/feed-c([0-9]+).xml$" /feed.php?cat=$1 last; rewrite "^/feed-b([0-9]+).xml$" /feed.php?brand=$1 last; rewrite "^/feed.xml$" /feed.php last; rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-])-([0-9]+)-(.+)-([a-zA-Z]+)(.).html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last; rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-])(.).html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last; rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.).html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last; rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.).html$" /category.php?id=$1&brand=$2&page=$3 last; rewrite "^/category-([0-9]+)-b([0-9]+)(.).html$" /category.php?id=$1&brand=$2 last; rewrite "^/category-([0-9]+)(.).html$" /category.php?id=$1 last; rewrite "^/goods-([0-9]+)(.).html" /goods.php?id=$1 last; rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.).html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last; rewrite "^/article_cat-([0-9]+)-([0-9]+)(.).html$" /article_cat.php?id=$1&page=$2 last; rewrite "^/article_cat-([0-9]+)(.).html$" /article_cat.php?id=$1 last; rewrite "^/article-([0-9]+)(.).html$" /article.php?id=$1 last; rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+).html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last; rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.).html" /brand.php?id=$1&cat=$2&page=$3 last; rewrite "^/brand-([0-9]+)-c([0-9]+)(.).html" /brand.php?id=$1&cat=$2 last; rewrite "^/brand-([0-9]+)(.).html" /brand.php?id=$1 last; rewrite "^/tag-(.).html" /search.php?keywords=$1 last; rewrite "^/snatch-([0-9]+).html$" /snatch.php?id=$1 last; rewrite "^/group_buy-([0-9]+).html$" /group_buy.php?act=view&id=$1 last; rewrite "^/auction-([0-9]+).html$" /auction.php?act=view&id=$1 last; rewrite "^/exchange-id([0-9]+)(.).html$" /exchange.php?id=$1&act=view last; rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.).html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last; rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.).html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last; rewrite "^/exchange-([0-9]+)-([0-9]+)(.).html$" /exchange.php?cat_id=$1&page=$2 last; rewrite "^/exchange-([0-9]+)(.).html$" /exchange.php?cat_id=$1 last; } 7)PHPWind伪静态 rewrite ^(.)-htm-(.)$ $1.php?$2 last; rewrite ^(.*)/simple/([a-z0-9_]+.html)$ $1/simple/index.php?$2 last; 8)SaBlog2.0伪静态 只带月份的归档 rewrite "^/date/([0-9]{6})/?([0-9]+)?/?$" /index.php?action=article&setdate=$1&page=$2 last; 无分类翻页 rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last; 分类 rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last; rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last; 归档、高级搜索 rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last; 全部评论、标签列表、引用列表 带分页 rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last; tags rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last; 文章 rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last; RSS rewrite ^/rss/([0-9]+)?/?$ /rss.php?cid=$1 last; rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last; 用户 rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last; rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last; 地图文件 rewrite sitemap.xml sitemap.php last; 自定义链接 rewrite ^(.*)/([0-9a-zA-Z-_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last; 9)SHOPEX伪静态 if (!-e $request_filename) { rewrite ^/(.+.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last; } 10)Typecho伪静态 if (-f $request_filename/index.html){ rewrite (.) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; }Nginx中的rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用。6. rewrite伪静态重写的执行顺序 [如下,前面的执行优先级依次大于后面的]location =location 完整路径location ^~ 路径location ~,或者location~* 正则顺序location 部分起始路径location /五、Apache伪静态配置和常用Rewrite伪静态规则1. Apache虚拟机配置及伪静态规则1)编辑Apache的conf目录下的httpd.conf文件。 去除"## LoadModule rewrite_module modules/mod_rewrite.so"的注释,开启mod_rewrite.so模块支持。 去除"## Include conf/extra/httpd-vhosts.conf"的注释,引入虚拟机配置文件。 2. 编辑httpd-vhost.conf <VirtualHost *:80> #发生错误时将发送邮件 #ServerAdmin
[email protected]
#文档根目录 DocumentRoot "/data/www/httpd" #域名 ServerName www.kevin.com #错误日志 ErrorLog "logs/error.log" #访问日志 CustomLog "logs/access.log" #配置rewrite相关选项 <Directory "/data/www/httpd"> #允许所有指令,这将允许.htaccess AllowOverride All #2.2的访问控制配置,先检查允许的条件,没有允许的全部禁止,中间只能有一个逗号不能有空格 #Order Allow,Deny #Allow from All #2.4的访问控制配置,效果等同以上 Require all granted </Directory> 3. 修改.htaccess #以下表示:如果存在目录或文件则直接访问,否则执行RewriteRule RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f #隐藏index.php RewriteRule ^(.*)$ index.php/$1 [L] 4. 重启apache服务2. Apache伪静态配置示例伪静态就是将原来动态化的页面址转换成为静态化的地址。 例如: 原访问地址:http://www.test.com/list.php?page=123&id=456 伪静态地址:http://www.test.com/list-123-456.html 操作方法: 1)首先确认Apache已经正确加载了mod_rewrite模块 检查httpd.conf中是否有LoadModule Rewrite_module modules/mod_Rewrite.so这段代码,如没有请加上。 2)策略配置。现有一个网站,根目录为/var/www/html,动态页面地址为/list.php?page=123&id=456,现在我们想要的效果是/list-123-456.html 2.1)使用httpd.conf来配置rewrite策略: 要使用httpd.conf文件来设置伪静态策略,可以直接在httpd.conf中写入如下代码,如果网站是配置在VirtualHost中, 则将这段代码加到对应的<VirtualHost hostname><VirtualHost>标签内: <IfModule mod_rewrite.c> #输入: list-123-456.html #输出: list.php?page=123&id=456 RewriteEngine on RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$1&id=$2 </IfModule> 添加完成后重启httpd服务后即可生效 2.2)使用.htaccess来配置rewrite策略 检查httpd.conf中的<Directory />标签配置,确认AllowOverride配置为All,这样才能启用.htaccess文件: <Directory /> Options FollowSymLinks AllowOverride All </Directory> 检查httpd.conf中的AccessFileName参数,确认为.htaccess AccessFileName .htaccess 在网站根目录下建立.htaccess文件,写入如下内容: RewriteEngine on RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1list.php?page=$2&id=$3 保存后重启httpd服务即可生效 常见问题: 1)为何都按上面设置了却还是无法静态化? 答:很有可能是因为别的目录设置项覆盖了<Directory />标签内的选项,导致.htaccess文件没起作用。 这个问题一般出现在网站根目录的Directory标签中,在这个例子中,可以检查<Directroy"/var/www/html">标签内的AllowOverride参数是否设置为All。 2).htaccess文件放在网站根目录,那子目录也可以实现伪静态吗? 答:.htaccess默认对所在目录下所有子目录生效,但是如果子目录中也放置了.htaccess文件,则该子目录下的访问规则以子目录中的.htaccess文件为准。3. Apache开启伪静态示例 (修改"AllowOverride ALL",打开支持.htaccess伪静态文件的功能)伪静态只是改变了URL的显示形式,实际上还是网站页面还是动态页面。伪静态的页面后缀可以是html 、 htm 或者是目录格式等。那么为什么要用伪静态呢? 有两点原因:1是seo优化,伪静态有利于搜索引擎的收录,能够增加网站优化效果;2是url看起来简单,网站URL给人专业性。 1)加载Rewrite模块: 在conf目录下httpd.conf中找到 LoadModule rewrite_module modules/mod_rewrite.so 2)允许在任何目录中使用“.htaccess”文件,将“AllowOverride”改成“All”(默认为“None”): ## AllowOverride controls what directives may be placed in .htaccess files. ## It can be “All”, “None”, or any combination of the keywords: ## Options FileInfo AuthConfig Limit # AllowOverride All ## 把 AllowOverride None 改为 AllowOverride All,重启一下apache服务器使配置生效,这样就支持.htaccess文件了。 3)Apache Rewrite模块的简单应用 Rewrite的所有判断规则均基于Perl风格的正则表达式,通过以下基础示例能写出符合自己跳转需求的代码。 3.1)请求跳转 目的是如果请求为.jsp文件,则跳转至其它域名访问。 例如: 访问www.clin003.com/a.php跳转至b.clin003.com/b.php网页,访问www.clin003.com/news/index.php跳转至b.clin003.com/news/index.php网页 注意: 不是使用HTML技术中的meta或者javascript方式,因为www.clin003.com/a.php这个文件并不存在,用的是Apache2.2服务器中的Rewrite模块。 修改 .htaccess或apche的配置文件httpd.conf文件,添加以下内容 RewriteEngine on #开启Rewrite模块 RewriteRule (.*)\.php$ http://b.clin003.com/$1\.jsp [R=301,L,NC] #截获所有.jsp请求,跳转到http://b.clin003.com/加上原来的请求再加上.php。R=301为301跳转,L为rewrite规则到此终止,NC为不区分大小写 3.2)域名跳转 如果请求为old.clin003.com下的所有URL,跳转至b.clin003.com RewriteEngine on #开启Rewrite模块 RewriteCond %{REMOTE_HOST} ^old.studenthome.cn$ [NC] #针对host为old.clin003.com的主机做处理,^为开始字符,$为结尾字符 RewriteRule (.*) http://b.clin003.com/$1 [R=301,L,NC] 3.3)防盗链 如果本网站的图片不想让其它网站调用,可以在 .htaccess或者apche的配置文件httpd.conf文件中添加以下内容 RewriteEngine on #开启Rewrite模块 RewriteCond %{HTTP_REFERER} !^$ #如果不是直接输入图片地址 RewriteCond %{HTTP_REFERER} !img.clin003.com$ [NC] #且如果不是img.clin003.com所有子域名调用的 RewriteCond %{HTTP_REFERER} !img.clin003.com/(.*)$ [NC] RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC] RewriteCond %{HTTP_REFERER} !google.com [NC] RewriteCond %{HTTP_REFERER} !google.cn [NC] RewriteCond %{HTTP_REFERER} !baidu.com [NC] RewriteCond %{HTTP_REFERER} !feedsky.com [NC] RewriteRule (.*)\.(jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf)$ http://clin003.com/err.jpg [R=301,L,NC] #截获所有.jpg或.jpeg……请求,跳转到http://clin003.com/err.jpg提示错误的图片,注:该图片不能在原域名下,也不能在该.htaccess文件有效控制的文件夹中 对配置做几点补充说明: L 表明当前规则是最后一条规则,停止分析以后重写 NC 不区分大小写 QSA 追加请求的字符串 ^ 表示语句开始 $ 表示语句的结束 3.4)不需要定义.htaccess文件 在Apache2\conf\httpd.conf 最后一行添加 RewriteEngine On RewriteRule ^(.*)-htm-(.*)$ $1.php?$24. Apache各种跳转(包括伪静态)的配置1)404跳转: #vim /etc/httpd/conf/httpd.conf 在虚拟主机配置里添加一行:ErrorDocument 404 /404.html 2)301跳转: 将不带www的跳转到带www的:在根目录下新建.htaccess文件,写入: Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^manyi.cc [NC] RewriteRule ^(.*)$ http://www.manyi.cc/$1 [L,R=301] 重定向到新域名: Options +FollowSymLinks RewriteEngine on RewriteRule ^(.*)$ http://www.manyi.cc/$1 [L,R=301] 3. 在httpd.conf配置文件中配置: <VirtualHost *:80> ServerName manyi.cc RedirectMatch permanent ^/(.*) http://www.manyi.cc/$1 </VirtualHost> 使用正则进行301伪静态配置:(将news.php?id=123这样的地址转向到news-123.html) Options +FollowSymLinks RewriteEngine on RewriteRule ^news-(.+)\.html$ news.php?id=$15. FastCGI加载PHP伪静态设置的注意事项默认的"RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]"规则在apache fastcgi模式下会导致"No input file specified". 修改成 RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] 这样就好了,地址正常重写。 #php api模式,服务器能识别PATH_INFO RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #php fastcgi模式 服务器不识别PATH_INFO RewriteRule ^(.*)$ index.php [E=PATH_INFO:$1,QSA,PT,L]当你发现自己的才华撑不起野心时,就请安静下来学习吧!参考资料:散尽浮华
2020年09月13日
2,892 阅读
0 评论
1 点赞
2020-09-08
带UI界面的Rclone——RcloneBrower
引言rclone是一款开源的网盘、对象存储同步工具,全平台支持(windows、mac、linux)官网地址: https://rclone.org/Github 仓库:https://github.com/rclone/rclone从官网首页可以查看到支持的对象存储,不过不支持百度云,或许百度网盘足够好用?除了限速。环境:Windows工具准备:rclone: https://rclone.org/downloads/rclone为命令模式RcloneBrower: https://github.com/kapitainsky/RcloneBrowser/一款跨平台Rclone GUI,给rclone套了一层皮,需配合rclone使用winfsp: http://www.secfs.net/winfsp/download/用来映射网盘某个路径到本地盘符步骤:一、配置rclone下载rclone解压,将rclone.exe所在目录加入系统环境变量Path,RcloneBrower会用到。执行rclone config添加要同步的对象存储。如果要同步的是google drive等被特殊关照的对象时,需配合✈和Proxifier使用,先来个Proxifier截图,详细配置自行。二、下载RcloneBrower解压打开,如果第一步配置正确,此时界面会入下图所示点击open(这里以google photo为例)具体命令可以查看rclone官方文档。三、下载winfsp下载后一路默认安装,RcloneBrower中的Mount操作将会用到该工具。结语其他网盘自行测试参考资料:OOIII
2020年09月08日
6,155 阅读
0 评论
0 点赞
2020-09-08
Typecho技巧:自定义独立页面模板实现归档、分类、标签
一、需求typecho 主题开发过程中,某些独立页面承担着这个站点的美化或者是导航作用。有些时候,用户自己增加的单独页面可以什么内容都没有,但是显示的时候,效果却能出来。此时用户自己增加的单独页面就承担了导航的作用,但是里面自己写的代码又成了美化作用。而独立页面中,文章分类、文章归档、标签、友链、关于这五个页面,前三个都是需要读取数据库,去显示内容的,这显然不能通过用户自己编辑内容去显示。此时文章模板 能够实现这种需求二、开发独立页面模板1、基本要求在模板文件夹新建一个 php 文件,如 page-category.php(文件名不做要求,但是我习惯使用 page- 这样的前缀标明)独立页面模板文件是需要有一个固定格式的 注释头部 的,这和 index.php 的固定头部要求是类似的@package custom 是固定的内容,必须存在,前面 文章分类模板 是在后台编辑的时候,选择模板列表的名字。** * 文章分类模板 * * @package custom */选择模板的时候如下:2、显示本单页的标题如果要显示一个单页的标题,则使用下面的代码即可:<?php $this->title() ?>3、是否需要显示用户编辑的页面内容用户在创建单独页面的时候,是能够编辑单独页面的内容,但是是否需要显示,则根据模板的需要,如果需要显示,则需要下面的语句:<?php $this->content(); ?>如果不需要显示用户编辑的内容,则直接去掉这个方法的调用即可。三、一些使用的模板一般来说,使用自定义模板都是实现特定的功能,比如上面提到的 文章分类、文章归档、标签等。1、文章分类<?php /** * 文章分类 * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); ?> <div class="col-md-12 text-center"> <div class="page-header"> <h2 class="page-title"><?php $this->title() ?></h2> <hr> </div> </div> <div class="col-md-12 "> <div class="page-wrapper"> <div class="categary-wrapper"> <div class="categary-content" itemprop="articleBody"> <div class="categary-list"> <?php $this->widget('Widget_Metas_Category_List')->parse('<div class="col-md-3 categary-item-wrapper"><div class="categary-item" ><a class="categary-item-link" href="{permalink}"> {name} · ({count})</a></div></div>'); ?> </div> </div> </div> </div> </div> <?php $this->need('footer.php'); ?>2、文章归档<?php /** * 文章存档 * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); ?> <div class="col-md-12 text-center"> <div class="page-header"> <h2 class="page-title"><?php $this->title() ?></h2> <hr> </div> </div> <div class="col-md-12"> <article class="page-wrapper" itemscope itemtype="http://schema.org/BlogPosting"> <div class="post-content" itemprop="articleBody"> <?php $stat = Typecho_Widget::widget('Widget_Stat'); Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize='.$stat->publishedPostsNum)->to($archives); $year=0; $mon=0; $i=0; $j=0; $output = '<div class="archives">'; while($archives->next()){ $year_tmp = date('Y',$archives->created); $mon_tmp = date('m',$archives->created); $y=$year; $m=$mon; if ($year > $year_tmp || $mon > $mon_tmp) { $output .= '</ul></div>'; } if ($year != $year_tmp || $mon != $mon_tmp) { $year = $year_tmp; $mon = $mon_tmp; $output .= '<div class="archives-item"><h4>'.date('Y年m月',$archives->created).'</h4><hr><ul class="archives_list">'; //输出年份 } $output .= '<li>'.date('d日',$archives->created).' <a href="'.$archives->permalink .'">'. $archives->title .'</a></li>'; //输出文章 } $output .= '</ul></div></div>'; echo $output; ?> </div> </article> </div><!-- end #main--> <?php $this->need('footer.php'); ?>3、标签<?php /** * 标签模板 * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); ?> <div class="col-md-12 text-center"> <div class="page-header"> <h2 class="page-title"><?php $this->title() ?></h2> <hr> </div> </div> <div class="col-md-12"> <div class="page-wrapper"> <div class="tags-wrapper" > <?php $this->widget('Widget_Metas_Tag_Cloud', 'sort=mid&ignoreZeroCount=1&desc=0')->to($tags); ?> <?php if($tags->have()): ?> <div class="tags-list"> <?php while ($tags->next()): ?> <div class="col-md-2 tag-item"><a href="<?php $tags->permalink(); ?>" rel="tag" class="size-<?php $tags->split(5, 10, 20, 30); ?>" title="<?php $tags->count(); ?> 个话题"><?php $tags->name(); ?> (<?php $tags->count(); ?>)</a></div> <?php endwhile; ?> <?php else: ?> <div><?php _e('没有任何标签'); ?></div> <?php endif; ?> </div> </div> </div><!-- end #main--> </div> <?php $this->need('footer.php'); ?>参考资料:Postbird
2020年09月08日
4,172 阅读
0 评论
9 点赞
2020-09-03
OneManager有趣的进阶玩法
OneManager是什么这是一个利用微软onedrive api将onedrive目录映射成一个云盘的程序,类似的程序有很多,比如OneIndex、Pyone、OnePoint等等。这个程序的特点是支持多种onedrive类型,可以部署在vps,heroku,以及腾讯云scf上。我的站点部署教程参考项目readme说明,网上一些博客也有不少教程,这不是本文的重点,本文主要讲的是部署好后的设置问题。后台设置登录后,在管理>设置里有一些自定义设置,有些人不清楚这些设置是干嘛的,这可以理解,毕竟项目的说明写的太简单了。注意本文的操作都是针对程序默认主题来说的,其他主题由于是第三方人员开发,不保证所有功能都能正常使用。adminloginpage自定义登录地址,设置后就会隐藏登录按钮(有些主题本来就没有登录按钮),登录时需要手动在网盘地址后加上?你设置的值进行登录。比如设置为abc,那么你只能通过http://xxx.com/xxx?abc地址来登录 。所以一旦设置就要记住你设置的值,不然连你自己也没法知道登录地址那就麻烦了。这个设置是为了防止别人通过默认的登录界面尝试登录你的网盘,设置本项后只要猜不到登录界面,即使别人知道登录密码也没用,多一道防护墙,让网盘更安全。autoJumpFirstDisk设置点击网盘标题时跳转到绑定的第一个盘还是当前绑定的网盘根目录。background自定义背景图片,填入一个图片的url地址,因为图片加载通常需要更多时间,为了速度考虑不建议放入大体积图片。backgroundm手机端显示的背景图片地址。customCss设置自定义css的地方,这里设置的css会作用于网盘所有页面。比如我想隐藏语言选项框:<style>.changelanguage{display:none}</style>customScript设置自定义js,会作用于所有页面。比如设置http重定向到https:<script type="text/javascript"> var targetProtocol = "https:"; if (window.location.protocol != targetProtocol) window.location.href = targetProtocol + window.location.href.substring(window.location.protocol.length); </script>customTheme通过url的方式引用html主题,比如你可以通过设置下面的地址来使用我的主题。https://cdn.jsdelivr.net/gh/kizx/onemoe-theme/onemoe.htmldisableChangeTheme设置为1后游客浏览时将不显示右下角的主题切换功能。disableShowThumb设置为1后将不显示缩略图的按钮和功能,对于云函数用户来说,建议设为1来关闭该功能,因为该功能可能点一下就是一分钱。hideFunctionalityFile设置为1后,游客浏览网盘时就会看不到read.md,head.md,head.ofm,foo.omf这些文件,这些文件是干嘛的后面会说。passfile设置密码文件名,比如这里设置为password.txt,那么在某一个目录下新建一个password.txt文件,其中写入密码,这样任何人在浏览这个网盘目录时都需要输入相应密码后才能访问。sitename设置网站名称。theme切换主题。timezone设置时区,国内可设置为8。以下是多盘设置diskname多盘在网盘界面显示的名称。domain_path当绑定多个域名时,可以使不同域名打开时访问不同目录。当然如果你只有一个域名也可以用,通过这种方式可以使当前域名访问一个指定子目录,和后面的public_path起到一样的作用。下面是两个域名的设置方法,中间用|隔开,如果有多个域名只设置一个域名时,未设置的域名好像也会只访问该目录,要访问根目录dirname设置为/。domain1.com:/dir1name|domain2.com:/dir2namedownloadencrypt设置为1时启用该功能,这样在设置了密码的目录下的文件虽然无法在网页端浏览,但可以通过具体的文件链接进行下载。guestup_path设置图床路径或者叫游客上传路径,设置后游客只能看到上传按钮看不到目录下的文件。public_path设置该盘的显示的根目录,默认为/,换个说法就是可以显示指定的文件夹,默认显示全部。比如我们只想将网盘下的public文件夹内容作为网盘,可以设置为/public/。有了这个功能,即使只有一个onedrive账号,我们也可以通过重复绑定同一个账号来生成多盘,然后每个盘的public_path设置为不同的路径,这样可以将一个盘的功能分开。还有一种特殊情况是我既想让游客上传文件,又想让游客看见上传后的文件目录,目前就只能通过这种方法将该目录设置到两个盘,一个盘作上传,一个盘作目录展示。进阶设置设置网站ico图标将favicon.ico图片放在网盘根目录下,如果你设置了多盘的的话,则需要在每个盘的根目录下都放置一个favicon.ico文件,新版的html主题只需要在绑定的第一个盘下面设置就行了。当然你也可以在customCss或customScript中进行全局设置:<link rel="icon" href="https://cloud.tencent.com/favicon.ico" type="image/x-icon"> 这里我使用了腾讯云的网站图标,你应该改为自己的favicon.ico图片地址。刷新自动切换背景图片这个是通过设置特殊的图片api来实现的,这些api每次刷新都会返回一张不同的图片,将后台background设置为这些api的url即可。网上类似的api有很多,以下是群友收集的免费图片api:https://api.ixiaowai.cn/api/api.php (二次元动漫) http://www.dmoe.cc/random.php(二次元随机图) https://api.ixiaowai.cn/mcapi/mcapi.php (menhera酱) https://api.ixiaowai.cn/gqapi/gqapi.php (风景) https://acg.yanwz.cn/wallpaper/api.php(二次元随机图)利用index.html设置自定义页面如果一个目录下有名为index.html的文件,则直接显示该文件,可以利用这个功能设置一个自定义页面或者用于隐藏一个特定页面,相当于部署了一个静态页面。设置顶部和底部说明文字在需要展示顶部说明的目录下新建一个head.md文件,在文件里写入说明内容即可,这是一个markdown文件,可以使用markdown语言进行书写。底部说明说明文字对应的是readme.md文件,规则与顶部文字一样。利用head.omf设置一言head.omf作用和head.md一样,区别是他不支持markdonw语言,但是支持html语言,可以写入html、css、js内容。在想展示一言的目录新建head.omf文件,然后写入以下内容:<p id="hitokoto">:D 获取中...</p> <script> fetch('https://v1.hitokoto.cn') .then(response => response.json()) .then(data => { const hitokoto = document.getElementById('hitokoto') hitokoto.innerText = data.hitokoto }) .catch(console.error) </script>以上是使用了https://developer.hitokoto.cn/ 的一言接口,你也可以尝试更换其他接口或者自建接口。利用foot.omf设置Valine评论使用Valine需要先注册LeanCloud并实名认证,然后新建应用获取AppID和AppKey。注:建议使用国际版具体过程参考:https://valine.js.org/quickstart.html然后新建foot.omf,写入以下内容(注意填入替换自己的AppID和AppKey):<script src='//unpkg.com/valine/dist/Valine.min.js'></script> <div id="vcomments"></div> <script> new Valine({ el: '#vcomments', appId: '你获取的AppID', appKey: '你获取的AppKey' }) </script>ps: 上面的js用的是unpkg的cdn,国内速度完全不行,建议改用jsdelivr的cdn<script src='//cdn.jsdelivr.net/npm/valine/dist/Valine.min.js'></script>如果对样式不满意,建议直接在omf文件写css美化。设置动态背景这里的动态背景指我们经常在一些网页见到的那种下雪、粒子线条、彩条等动态背景,一般是通过js实现的,可以自己在网上找找现成的教程,js我不会,这里只展示一种我找到的动态彩条背景。我将下面的代码写在了foot.omf中,可以访问https://pan.2bboy.com/home/test/ 查看其效果。<script size="90" alpha="0.5" zIndex="0" src="https://pan.2bboy.com/ppx/test/ribbon.js" type="text/javascript" charset="utf-8"></script>其中最重要的是 https://pan.2bboy.com/ppx/test/ribbon.js 这个js文件,我将他放在网盘目录下,你应该下载该文件放在自己的云空间里,然后替换引用的地址。如果将代码放在omf文件里则只能在当前目录有效果,设置在后台的customScript中就可以全局生效了。美化自定义登录页面修改common.php相应地方,添加style和br$html .= ' <style>body{background-image:linear-gradient(60deg,#343b44 0%,#485563 100%);background-attachment:fixed;color:#343b44}body>div{position:absolute;text-align:center;background-color:rgba(221,221,221,.5);border-radius:20px;width:75vw;max-width:500px;height:350px;margin:auto;top:25%;bottom:50%;left:0;right:0}body>div:hover{box-shadow:3px 3px 6px 3px rgba(0,0,0,.3)}h4{font-size:40px}input{font-size:20px;margin:2%auto;border:#343b44 2px solid;border-radius:10px;padding:10px;height:50px;text-align:center}input:last-of-type{color:#343b44;height:50px;width:80px;font-weight:800}input:hover:last-of-type{cursor:pointer;color:#ddd;background-color:#485563}</style> <body> <div> <center><h4>'.getconstStr('InputPassword').'</h4> <form action="" method="post"> <div> <input name="password1" type="password"/> </br> <input type="submit" value="'.getconstStr('Login').'"> </div> </form> </center> </div> ';提示游客上传文件时只能单个上传,不能批量上传。由于scf的缓存系统,在scf上进行某项改动后有时候不会立马生效,或者刷新后时而生效时而不生效,只要多等一会儿,等旧缓存自己失效就好了。php格式的主题为旧版主题,许多功能不支持,html格式的主题为新版主题,不同主题的作者更新频率和支持功能都可能不同,功能测试请以最新版本的默认主题为准。参考资料:醉后的星星
2020年09月03日
8,259 阅读
1 评论
8 点赞
2020-08-17
You-Get使用教程——下载各个网站的视频(优酷、YouTube等等)
You-Get 乃一小小哒命令行程序,提供便利的方式来下载网络上的媒体信息。利用you-get下载这个网页的视频:$ you-get http://www.fsf.org/blogs/rms/20140407-geneva-tedx-talk-free-software-free-society Site: fsf.org Title: TEDxGE2014_Stallman05_LQ Type: WebM video (video/webm) Size: 27.12 MiB (28435804 Bytes) Downloading TEDxGE2014_Stallman05_LQ.webm ... 100.0% ( 27.1/27.1 MB) ├████████████████████████████████████████┤[1/1] 12 MB/s为什么你要好好的用You-get:你欢喜于互联网上的富媒体内容,并为个人寻欢而储存你喜悦观看的视频,然而不得保存;对个人设备无从控制,此乃违背开放互联网之行为你寻求解脱于闭源软件或JavaScript代码,并禁止Flash运行你为黑客精神与自由软件而欣喜you-get之功用:下载流行网站之音视频,例如YouTube, Youku, Niconico,以及更多. (查看完整支持列表)于您心仪的媒体播放器中观看在线视频,脱离浏览器与广告下载您喜欢的网页上的图片下载任何非HTML内容,例如二进制文件心动? 现在安装 并 查看使用范例.使用Python编程?敬请查看 源代码 并fork!安装绪论以下乃必要依赖,需要单独安装,除非于Windows下使用预包装包:Python 3FFmpeg (强烈推荐) or Libav(可选) RTMPDump选项 1: 通过pip安装you-get之官方版本通过PyPI分发, 可从PyPI镜像中通过pip 包管理器安装. 须知您务必使用版本3的 pip:$ pip3 install you-get 选项 2: 使用预装包(仅供Windows)exe (单独文件) 或 7z (包括所有依赖) 可从https://github.com/soimort/you-get/releases/latest 下载.选项 3: 于GitHub下载您可选择稳定版 (与PyPI最新版等同) 或 开发版 (更多的热补丁与不稳定功能)的you-get. 解压并将含有you-get的目录加入PATH.或者, 运行$ make install以安装you-get 于永久路径.选项 4: Git clone即使您不常使用Python,作为开发者,也请使用此方法。$ git clone git://github.com/soimort/you-get.git将目录加入 PATH, 或运行 make install 以安装you-get 于永久路径.升级考虑到 you-get 安装方法之差异, 请使用:$ pip3 install --upgrade you-get或下载最新更新:$ you-get https://github.com/soimort/you-get/archive/master.zip开始下载视频当观赏感兴趣之视频,您可以使用 --info/-i 以查看所有可用画质与格式、s:$ you-get -i 'https://www.youtube.com/watch?v=jNQXAC9IVRw' site: YouTube title: Me at the zoo streams: # Available quality and codecs [ DEFAULT ] _________________________________ - itag: 43 container: webm quality: medium size: 0.5 MiB (564215 bytes) # download-with: you-get --itag=43 [URL] - itag: 18 container: mp4 quality: medium # download-with: you-get --itag=18 [URL] - itag: 5 container: flv quality: small # download-with: you-get --itag=5 [URL] - itag: 36 container: 3gp quality: small # download-with: you-get --itag=36 [URL] - itag: 17 container: 3gp quality: small # download-with: you-get --itag=17 [URL]标有DEFAULT 为默认画质。如认同,可下载:$ you-get 'https://www.youtube.com/watch?v=jNQXAC9IVRw' site: YouTube title: Me at the zoo stream: - itag: 43 container: webm quality: medium size: 0.5 MiB (564215 bytes) # download-with: you-get --itag=43 [URL] Downloading zoo.webm ... 100.0% ( 0.5/0.5 MB) ├████████████████████████████████████████┤[1/1] 7 MB/s Saving Me at the zoo.en.srt ...Done.(如YouTube视频带有字幕,将被一同下载,以SubRip格式保存.)或,如您希望其他格式(mp4),请使用其他提示选项:$ you-get --itag=18 'https://www.youtube.com/watch?v=jNQXAC9IVRw'注意:目前,格式选择没有大规模铺开;默认选项为最高画质.ffmpeg为必要依赖,以下载流式视频以及合并分块视频(例如,类似Youku), 以及YouTube的1080p或更高分辨率.如不希望you-get合并视频,使用--no-merge/-n.下载其他内容如你有URL,可以直接使用:$ you-get https://stallman.org/rms.jpg Site: stallman.org Title: rms Type: JPEG Image (image/jpeg) Size: 0.06 MiB (66482 Bytes) Downloading rms.jpg ... 100.0% ( 0.1/0.1 MB) ├████████████████████████████████████████┤[1/1] 127 kB/s或者, you-get将自动检查网页,下载一切有可能感兴趣的内容:$ you-get http://kopasas.tumblr.com/post/69361932517 Site: Tumblr.com Title: kopasas Type: Unknown type (None) Size: 0.51 MiB (536583 Bytes) Site: Tumblr.com Title: tumblr_mxhg13jx4n1sftq6do1_1280 Type: Portable Network Graphics (image/png) Size: 0.51 MiB (536583 Bytes) Downloading tumblr_mxhg13jx4n1sftq6do1_1280.png ... 100.0% ( 0.5/0.5 MB) ├████████████████████████████████████████┤[1/1] 22 MB/s注意:此功能为测试性,远未完成。对于类似Tumblr和Blogger的大图有效,但是没有办法为所有网站建立通用格式.在Google Videos搜索并下载you-get可以吃任何东西. 如果不是合法的URL, you-get将在Google查找并下载最相关视频. (可能不是最心仪的,但是很有可能)$ you-get "Richard Stallman eats"暂停与恢复下载可以使用Ctrl+C 暂停下载.临时的.download文件将保存于输出目录。下次使用you-get传入相同参数时,下载将从上次继续开始. 如果下载已经完成 (临时的.download 扩展名消失), you-get将忽略下载.用--force/-f强行重下载. (注意: 将覆盖同名文件或临时文件!)设置输出文件名或路径使用--output-dir/-o 设定路径, --output-filename/-O 设定输出文件名:$ you-get -o ~/Videos -O zoo.webm 'https://www.youtube.com/watch?v=jNQXAC9IVRw'提示:如果原视频标题含有与系统不兼容字符,十分有效.也可以帮助使用脚本批量下载于指定目录和文件名.代理设置使用 --http-proxy/-x为you-get设置HTTP代理:$ you-get -x 127.0.0.1:8087 'https://www.youtube.com/watch?v=jNQXAC9IVRw'然而系统代理 (即系统变量http_proxy) 自动使用. 使用--no-proxy强行关闭.提示:如果经常使用代理 (网络封锁了部分网站), 考虑将you-get和 proxychains 一同使用,并设置alias you-get="proxychains -q you-get" (于命令行).对于某些网站(例如Youku), 如果你需要下载仅供中国大陆观看的视频, 可以使用 --extractor-proxy/-y单独为解析器设置代理.可以使用 -y proxy.uku.im:8888 (鸣谢: Unblock Youku 项目).观看视频使用 --player/-p 将视频喂进播放器, 例如 mplayer 或者 vlc,而不是下载:$ you-get -p vlc 'https://www.youtube.com/watch?v=jNQXAC9IVRw'或者你想在浏览器中观看而不希望看广告或评论区:$ you-get -p chromium 'https://www.youtube.com/watch?v=jNQXAC9IVRw'提示:可以使用 -p 开启下载工具,例如 you-get -p uget-gtk 'https://www.youtube.com/watch?v=jNQXAC9IVRw', 虽然有可能不灵.加载cookie并非所有视频可供任何人观看。如果需要登录以观看 (例如, 私密视频), 可能必须将浏览器cookie通过--cookies/-c 加载入 you-get.注意:目前我们支持两种cookie格式:Mozilla cookies.sqlite 和 Netscape cookies.txt.复用解析数据使用 --url/-u 获得页面所有可下载URL列表. 使用 --json以获得JSON格式.警告:目前此功能未定型,JSON格式未来有可能变化.支持网站网站URL视频?图像?音频?YouTubehttps://www.youtube.com/✓ Twitterhttps://twitter.com/✓✓ VKhttp://vk.com/✓ Vinehttps://vine.co/✓ Vimeohttps://vimeo.com/✓ Vidtohttp://vidto.me/✓ Veohhttp://www.veoh.com/✓ Tumblrhttps://www.tumblr.com/✓✓✓TEDhttp://www.ted.com/✓ SoundCloudhttps://soundcloud.com/ ✓Pinteresthttps://www.pinterest.com/ ✓ MusicPlayOnhttp://en.musicplayon.com/✓ MTV81http://www.mtv81.com/✓ Mixcloudhttps://www.mixcloud.com/ ✓Metacafehttp://www.metacafe.com/✓ Magistohttp://www.magisto.com/✓ Khan Academyhttps://www.khanacademy.org/✓ JPopsuki TVhttp://www.jpopsuki.tv/✓ Internet Archivehttps://archive.org/✓ Instagramhttps://instagram.com/✓✓ Heavy Music Archivehttp://www.heavy-music.ru/ ✓Google+https://plus.google.com/✓✓ Freesoundhttp://www.freesound.org/ ✓Flickrhttps://www.flickr.com/✓✓ Facebookhttps://www.facebook.com/✓ eHowhttp://www.ehow.com/✓ Dailymotionhttp://www.dailymotion.com/✓ CBShttp://www.cbs.com/✓ Bandcamphttp://bandcamp.com/ ✓AliveThaihttp://alive.in.th/✓ interest.mehttp://ch.interest.me/tvn✓ 755<br/>ナナゴーゴーhttp://7gogo.jp/✓✓ niconico<br/>ニコニコ動画http://www.nicovideo.jp/✓ 163<br/>网易视频<br/>网易云音乐http://v.163.com/br/http://music.163.com/✓ ✓56网http://www.56.com/✓ AcFunhttp://www.acfun.tv/✓ Baidu<br/>百度贴吧http://tieba.baidu.com/✓✓ 爆米花网http://www.baomihua.com/✓ bilibili<br/>哔哩哔哩http://www.bilibili.com/✓ Dilidilihttp://www.dilidili.com/✓ 豆瓣http://www.douban.com/ ✓斗鱼http://www.douyutv.com/✓ 凤凰视频http://v.ifeng.com/✓ 风行网http://www.fun.tv/✓ iQIYI<br/>爱奇艺http://www.iqiyi.com/✓ 激动网http://www.joy.cn/✓ 酷6网http://www.ku6.com/✓ 酷狗音乐http://www.kugou.com/ ✓酷我音乐http://www.kuwo.cn/ ✓乐视网http://www.letv.com/✓ 荔枝FMhttp://www.lizhi.fm/ ✓秒拍http://www.miaopai.com/✓ MioMio弹幕网http://www.miomio.tv/✓ 痞客邦https://www.pixnet.net/✓ PPTV聚力http://www.pptv.com/✓ 齐鲁网http://v.iqilu.com/✓ QQ<br/>腾讯视频http://v.qq.com/✓ 阡陌视频http://qianmo.com/✓ Sina<br/>新浪视频<br/>微博秒拍视频http://video.sina.com.cn/br/http://video.weibo.com/✓ Sohu<br/>搜狐视频http://tv.sohu.com/✓ 天天动听http://www.dongting.com/ ✓Tudou<br/>土豆http://www.tudou.com/✓ 虾米http://www.xiami.com/ ✓阳光卫视http://www.isuntv.com/✓ 音悦Taihttp://www.yinyuetai.com/✓ Youku<br/>优酷http://www.youku.com/✓ 战旗TVhttp://www.zhanqi.tv/lives✓ 央视网http://www.cntv.cn/✓ 对于不在列表的网站,通用解析器将寻找并下载感兴趣之内容.已知问题如果 you-get 出现问题,不要惊慌. (是的,问题一直存在!)看看是不是在 https://github.com/soimort/you-get/wiki/Known-Bugs里面, 搜索 开放Issue. 如果没人报告,开个新issue, 加上详细的命令行输出.参与我们使用Gitter #soimort/you-get (如何为Gitter 设置IRC客户端 ). 如果是个关于 you-get 的小问题, 在这里问.我们欢迎各种pull requestse. 然而请注意:你要向 develop 分支发PR.记得rebase.写出详细文档,如果可以,给出一些测试URL.commit message格式优美,清晰可读. 如果不知道,看看以往的.我们不会强制你签署 CLA, 但是你必须确保你的代码可以被合法分发(使用 MIT 协议).法律问题本软件使用 MIT 协议.请特别注意:THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.(一个中文翻译可在http://lucien.cc/?p=15 查询。)人话:如果你使用本软件进行盗版行为,或者非法行径,作者不为你负责.我们仅提供代码, 如何使用请自行考虑.
2020年08月17日
2,755 阅读
0 评论
1 点赞
2020-08-08
如何提取OneDrive文件直链?
原理原链接:https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx直链:https://xxxx-my.sharepoint.com/personal/xx_xx_xx/_layouts/52/download.aspx?share=xxxxxxxxxx(这一种更有效)或https://xxxx-my.sharepoint.com/:x:/g/personal/xx_xx_xx/xxxxxxxxxx?download=1(这是重定向跳转至直链)Python实现我自己编写的一个Python小工具源码:# 原理:https://www.skyqian.com/archives/OneDrive-straight.html import re def judgeLink(url): reg1 = r'https://.+sharepoint\.com' reg2 = r'personal/(\w+?)/' reg3 = r'.*/(\S+)' reg4 = r'com/:(\w):/' p1 = re.findall(reg1, url)[0] p2 = re.findall(reg2, url)[0] p3 = re.findall(reg3, url)[0] if '?' in p3: p3 = re.findall(r'(\S+?)\?', p3)[0] if re.findall(reg4, url)[0] == 'f': return "抱歉,你所输入链接分享的是文件夹,直链生成仅对单文件有效。" return p1 + '/personal/' + p2 + '/_layouts/52/download.aspx?share=' + p3 if __name__ == "__main__": url = input("请输入你的OneDrive单文件分享链接:") try: url_judged = judgeLink(url) print(f"\n>>> {url_judged}") except: print("\n>>> 请检查你的输入链接是否正确?") Telegram机器人打开机器人 @Complex_1ove_bot发送/getOneDriveStraight + 单文件的分享链接通过搭建目录程序获得直链OneManager(推荐,支持一键部署)OneManager的进阶玩法:🔗传送门ShareList这个比较个性,可以基于API或者分享链接挂载,个人觉得这种方式会比挂载整个网盘方便管理,也有利于保护其他文件。sharelist支持Google Drive、OneDrive(包括世纪互联)、天翼云、蓝奏云、GitHub、WebDAV、本地文件等。Oneindex基于php,应该是这类项目中最早流行起来的,功能比较完善,但是实测OneDrive个人版有一部分中文目录读不出来(2019年下半年),作者donwa前段时间删除了这个项目,原因未知,链接为他人的备份。oneindex仅支持OneDrive(个人、企业版或教育版/工作或学校帐户,世纪互联版方法请搜索)。PyOne基于Python的项目,个人觉得比oneindex好看一点点,并且很早就支持离线下载,不过跟oneindex一样有读不出目录的问题(2019年下半年)。PyOne仅支持OneDrive(包括世纪互联)。OLAINDEX基于php,没发现前面所说读不出目录的问题。OLAINDEX仅支持OneDrive(包括世纪互联)。CuteOne基于Python,也有php版本,很好看,而且做出了模块化,甚至可以当作电影分享站,不过链接OneDrive个人版有bug导致刷不出缓存,其实很简单,然而作者不打算修的亚子……CuteOne仅支持OneDrive(包括世纪互联,其中个人版需手动修改文件)。OneListVicer大佬的项目,基于Python,也有go版本,据说可以缓解一些API过度调用的问题,未测试。OneList仅支持OneDrive(包括世纪互联)。Goindex基于js和CF Workers,未测试过,和oneindex同一作者,同样已删库,链接为他人备份。goindex仅支持Google Drive。GDIndex基于js和CF Workers,未测试过。GDIndex仅支持Google Drive。Zfile(前端 后端)支持阿里云 OSS、FTP、华为云 OBS、本地存储、MINIO、OneDrive 国际 /家庭 /个人版、OneDrive 世纪互联版、七牛云 KODO、腾讯云 COS、又拍云 USS。Fast.io这是一个免费的静态空间网站,也可以用来挂载网盘。Fast.io支持Google Drive、OneDrive、Github、Dropbox、MediaFire、BOX。JustList比较简洁,支持OneDrive(国际版、世纪互联)和天翼云盘。OneDriveFly仅支持OneDrive,可以部署到QCloud SCF、Aliyun FC、Heroku,计划支持Cloudflare Workers、Google Cloud Functions、Azure Functions。SuperOne仅支持OneDrive,内置API,无需申请。OneindexNOneindex的继承版本,加入aria2下载等功能。YukiDrive支持OneDrive和Sharepoint,前后端分离。
2020年08月08日
9,161 阅读
1 评论
16 点赞
2020-08-01
如何将必应Bing每日图片设置为网站背景
前言 Bing每日图片相信每位使用过必应搜索的小伙伴都了解,网上也有很多关于如何将Bing每日图片设置为电脑壁纸的教程,甚至微软专门推出过一款Bing桌面的应用方便大家将必应的美图设置为电脑桌面壁纸。因为图片每日都不同并且每个图片后面都伴随一个小故事,受到了很多小伙伴的欢迎。 那么,如果可以把Bing的每日图片设置为博客背景会不会很酷炫呢?懒人现成接口1366*768分辨率图片地址https://api.dujin.org/bing/1366.php1920*1080分辨率图片地址https://api.dujin.org/bing/1920.php手机标准分辨率1080*1920图片地址https://api.dujin.org/bing/m.php这两个API接口可以直接把它当做一个链接来用,插入如下代码:<img src="https://api.dujin.org/bing/1366.php" alt="Bing每日图片" /> <img src="https://api.dujin.org/bing/1920.php" alt="Bing每日图片超高清" /> <img src="https://api.dujin.org/bing/m.php" alt="Bing每日图片手机超高清" />参考资料:[缙哥哥博客]https://www.dujin.org/3618.html自己动手丰衣足食接口 通过抓包,我们可以发现这个链接https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 目前,国内版和国际版的每日图片内容显示一致,如果你想获取国际版的每日图片,只需将网址中的“cn”替换为“www”即可。 这里需要注意,链接中idx=0表示是显示当天的时间,如果要显示昨天的就将idx=0改为idx=1,以此类推。必应每日图片支持查看历史15天以内的图片。 抓包显示结果:{"images":[{"startdate":"20180917","fullstartdate":"201809171600","enddate":"20180918","url":"/az/hprichbg/rb/CalidrisCanutus_ZH-CN10519054459_1920x1080.jpg","urlbase":"/az/hprichbg/rb/CalidrisCanutus_ZH-CN10519054459","copyright":"在设得兰群岛觅食的红腹滨鹬,苏格兰 (© Andrew Parkinson/Minden Pictures)","copyrightlink":"http://www.bing.com/search?q=%E7%BA%A2%E8%85%B9%E6%BB%A8%E9%B9%AC&form=hpcapt&mkt=zh-cn","title":"","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20180917_CalidrisCanutus%22&FORM=HPQUIZ","wp":true,"hsh":"0a7f98e36e11f76ca5baea28f6ff86ac","drk":1,"top":1,"bot":1,"hs":[]}],"tooltips":{"loading":"正在加载...","previous":"上一个图像","next":"下一个图像","walle":"此图片不能下载用作壁纸。","walls":"下载今日美图。仅限用作桌面壁纸。"}}获取图片 有了接口我们就可以直接利用正则表达式去匹配相关字符串了。 以下是将必应每日图片通过php直接输出分辨率为1366X768图片的代码:<?php $str=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1'); if (preg_match("/<url>(.+?)<\/url>/ies", $str, $matches)) { $imgurl='https://cn.bing.com'.$matches[1]; } if ($imgurl) { header('Content-Type: image/JPEG'); @ob_end_clean(); @readfile($imgurl); @flush(); @ob_flush(); exit(); } else { exit('error'); } ?> 考虑到直接输出图片会占用一定的主机带宽,我们也可以将Bing图片做302跳转。以下是通过php将输出图片302定向到Bing的代码:<?php $str=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1'); if (preg_match("/<url>(.+?)<\/url>/ies", $str, $matches)) { $imgurl='https://cn.bing.com'.$matches[1]; } if ($imgurl) { header("Location: $imgurl"); //输出302跳转 } else { exit('error'); } ?> 根据需要复制上面两段代码中的任意1段,将文件保存为bg.php或任意名称.php上传到你的服务器。访问http://*.com/bg.php就可以看到必应每日图片了。 考虑到有些网友的需求,增加了输出1920X1080高清图片的php代码。<?php $str=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1'); if (preg_match("/<urlBase>(.+?)<\/urlBase>/ies", $str, $matches)) { $imgurl='https://cn.bing.com'.$matches[1].'_1920x1080.jpg'; } if ($imgurl) { header('Content-Type: image/JPEG'); @ob_end_clean(); @readfile($imgurl); @flush(); @ob_flush(); exit(); } else { exit('error'); } ?>源码下载代码已上传至Github,下载地址:https://github.com/fanmingming/bing设置背景 设置网站背景的方法有很多,有些博客内置了设置背景URL,只要将这个URL地址填写为我们上传好的php绝对路径就大功告成了!博主用的是Gridea静态博客,很便捷,将代码传至服务器,填写绝对路径即可。参考资料:范明明's Blog
2020年08月01日
1,420 阅读
0 评论
2 点赞
2020-03-08
使用rclone魔改版挂载世纪互联
引言rclone可以挂载OneDrive,但可惜的是国际版在国内裸连的速度不是很理想。所以国内又专门代理的世纪互联,如果rclone可以挂载世纪互联OneDrive,就会是一件很美的事情。使用方法一、世纪互联空全局订阅获取Azure+自建独享API适用于可以使用API,但本身子账号不能创建API的。可以撸个空全局,利用空全局账号创建API来供不能创建API的子号使用。打开比较面向中小企业的中国版本计划和价格 随便选个套餐立即购买然后按提示注册新账号,左上角点进去,进入管理,把付款取消掉。API权限我们需要空全局管理员点击 代表XXXX授予管理员同意WINDOWS平台rclone获取token时需要在后面加上--onedrive-is-21vianet-version=true示范如下rclone authorize "onedrive" "client_ID" "client_secret" --onedrive-is-21vianet-version=true二、世纪互联 OneDrive 获取 CLIENT_ID 及 CLIENT_SECRET打开 https://portal.azure.cn/ 登陆并按以下步骤:左侧找到 Azure Active Directory 点击左侧找到 应用注册上方找到 新注册 点击名称:onedrive受支持的账户类型: 任何组织目录(任何 Azure AD 目录 - 多租户)中的帐户(第二个)重定向 URL:http://localhost:53682点击注册 找到 应用程序(客户端) ID 复制client_ID保存左侧找到 证书和密码 点击下方 客户端密码 - 新客户端密码说明:onedrive截止期限:默认 1年内点击 添加,值 客户端密码 复制client_secret保存左侧找到 API 权限 点击添加权限 - Microsoft Graph - 委托的权限 - Files (7)全部勾选选择应用程序权限 在下方Files里选择 Files.Read.All和Files.ReadWrite.All回到界面会发现该权限处于未授权状态,我们需要全局管理员点击 代表XXXX授予管理员同意Files.Read Files.Read.All Files.Read.Selected Files.ReadWrite Files.ReadWrite.All Files.ReadWrite.AppFolder Files.ReadWrite.Selected三、安装配置 Rclone魔改版Rclone 世纪互联版地址:兼容世纪互联的 Rclone预编译兼容世纪互联的 Rclone v1.50.2Linux 32位 | Linux 64位 | Windows 32位 | Windows 64位下载解压上传到 /usr/bin 目录,然后chmod +x /usr/bin/rclone rclone config完整配置过程如下Microsoft Windows [版本 10.0.17763.316] (c) 2018 Microsoft Corporation。保留所有权利。 C:\Users\user>cd C:\Users\user\Desktop\rclone-v1.50.2-windows-amd64-21vianet C:\Users\user\Desktop\rclone-v1.50.2-windows-amd64-21vianet>rclone config 2020/02/01 13:46:21 NOTICE: Config file "C:\\Users\\user\\.config\\rclone\\rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n name> onedrive_cn Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / 1Fichier \ "fichier" 2 / Alias for an existing remote \ "alias" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc) \ "s3" 5 / Backblaze B2 \ "b2" 6 / Box \ "box" 7 / Cache a remote \ "cache" 8 / Citrix Sharefile \ "sharefile" 9 / Dropbox \ "dropbox" 10 / Encrypt/Decrypt a remote \ "crypt" 11 / FTP Connection \ "ftp" 12 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 13 / Google Drive \ "drive" 14 / Google Photos \ "google photos" 15 / Hubic \ "hubic" 16 / JottaCloud \ "jottacloud" 17 / Koofr \ "koofr" 18 / Local Disk \ "local" 19 / Mail.ru Cloud \ "mailru" 20 / Mega \ "mega" 21 / Microsoft Azure Blob Storage \ "azureblob" 22 / Microsoft OneDrive \ "onedrive" 23 / OpenDrive \ "opendrive" 24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 25 / Pcloud \ "pcloud" 26 / Put.io \ "putio" 27 / QingCloud Object Storage \ "qingstor" 28 / SSH/SFTP Connection \ "sftp" 29 / Transparently chunk/split large files \ "chunker" 30 / Union merges the contents of several remotes \ "union" 31 / Webdav \ "webdav" 32 / Yandex Disk \ "yandex" 33 / http Connection \ "http" 34 / premiumize.me \ "premiumizeme" Storage> 22 ** See help for onedrive backend at: https://rclone.org/onedrive/ ** Microsoft App Client Id Leave blank normally. Enter a string value. Press Enter for the default (""). client_id> 6b57cb03-3791-4823-9ce9-5dd027e***** Microsoft App Client Secret Leave blank normally. Enter a string value. Press Enter for the default (""). client_secret> l05:IBoAAVh4]Y]4M_?9lgw-L8****** OneDrive operated by 21Vianet (世纪互联). Enter a boolean value (true or false). Press Enter for the default ("false"). is_21vianet_version> true Edit advanced config? (y/n) y) Yes n) No y/n> y Chunk size to upload files with - must be multiple of 320k (327,680 bytes). Above this size files will be chunked - must be multiple of 320k (327,680 bytes). Note that the chunks will be buffered into memory. Enter a size with suffix k,M,G,T. Press Enter for the default ("10M"). chunk_size> 10M The ID of the drive to use Enter a string value. Press Enter for the default (""). drive_id> The type of the drive ( personal | business | documentLibrary ) Enter a string value. Press Enter for the default (""). drive_type> business Set to make OneNote files show up in directory listings. By default rclone will hide OneNote files in directory listings because operations like "Open" and "Update" won't work on them. But this behaviour may also prevent you from deleting them. If you want to delete OneNote files or otherwise want them to show up in directory listing, set this option. Enter a boolean value (true or false). Press Enter for the default ("false"). expose_onenote_files> Remote config Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config. Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes n) No y/n> Y If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=3-n1fmI2XA7QsjnhQAjoQw Log in and authorize rclone for access Waiting for code... Got code Choose a number from below, or type in an existing value 1 / OneDrive Personal or Business \ "onedrive" 2 / Root Sharepoint site \ "sharepoint" 3 / Type in driveID \ "driveid" 4 / Type in SiteID \ "siteid" 5 / Search a Sharepoint site \ "search" Your choice> 1 Found 1 drives, please select the one you want to use: 0: OneDrive (business) id=b!Yb3jWYP2_EOgiOjYxlsv4iz1Y8ZSfhlEm48kp98Ew0Dzv4TUrSwSSK1sL5j***** Chose drive to use:> 0 Found drive 'root' of type 'business', URL: https://*****-my.sharepoint.cn/personal/***_****_partner_onmschina_cn/Documents Is that okay? y) Yes n) No y/n> y -------------------- [onedrive_cn] type = onedrive client_id = 6b57cb03-3791-4823-9ce9-5dd027e***** client_secret = l05:IBoAAVh4]Y]4M_?9lgw-L8****** is_21vianet_version = true chunk_size = 10M drive_type = business token = {"access_token":"eyJ0eXAiOiJKV1Q********BtBs2OM8B1Euv7SAA","expiry":"2020-02-01T14:50:32.8151941+08:00"} drive_id = b!Yb3jWYP2_EOgiOjYxlsv4iz1Y8****************UrSwSSK1sL5jmrG0I -------------------- y) Yes this is OK e) Edit this remote d) Delete this remote y/e/d> y Current remotes: Name Type ==== ==== onedrive_cn onedrive e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q> q配置文件C:\Users\user\.config\rclone\rclone.conf格式如下[onedrive_cn] type = onedrive client_id = 6b57cb03-3791-4823-9ce9-5dd027e***** client_secret = l05:IBoAAVh4]Y]4M_?9lgw-L8****** is_21vianet_version = true chunk_size = 10M drive_type = business token = {"access_token":"eyJ0eXAiOiJKV1Q********BtBs2OM8B1Euv7SAA","expiry":"2020-02-01T14:50:32.8151941+08:00"} drive_id = b!Yb3jWYP2_EOgiOjYxlsv4iz1Y8****************UrSwSSK1sL5jmrG0I四、挂载apt -y update && apt install fuse挂载命令:rclone mount onedrive:/ /mnt/ --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000后台挂载命令:nohup rclone mount onedrive:/ /mnt --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 &卸载命令:fusermount -qzu LocalFolder onedriveRclone 开机启动(脚本来自:Rat’s Blog,二次修改支持多网盘挂载)nano /etc/init.d/rcloned文本内容如下#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH NAME_BIN="rclone" ### BEGIN INIT INFO # Provides: rclone # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start rclone at boot time # Description: Enable rclone by daemon. ### END INIT INFO NAME="" #rclone name名 REMOTE='' #远程文件夹 LOCAL='' #挂在地址 NAME_1="" REMOTE_1='' LOCAL_1='' Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" Info="${Green_font_prefix}[信息]${Font_color_suffix}" Error="${Red_font_prefix}[错误]${Font_color_suffix}" RETVAL=0 check_running(){ PID="$(ps -C $NAME_BIN -o pid= |head -n1 |grep -o '[0-9]\{1,\}')" if [[ ! -z ${PID} ]]; then return 0 else return 1 fi } do_start(){ check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN (PID ${PID}) 正在运行..." && exit 0 else fusermount -zuq $LOCAL >/dev/null 2>&1 mkdir -p $LOCAL /usr/bin/rclone mount $NAME:$REMOTE $LOCAL --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 & sleep 2s fusermount -zuq $LOCAL_1 >/dev/null 2>&1 mkdir -p $LOCAL_1 /usr/bin/rclone mount $NAME_1:$REMOTE_1 $LOCAL_1 --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 & check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN 启动成功 !" else echo -e "${Error} $NAME_BIN 启动失败 !" fi fi } do_stop(){ check_running if [[ $? -eq 0 ]]; then kill -9 ${PID} RETVAL=$? if [[ $RETVAL -eq 0 ]]; then echo -e "${Info} $NAME_BIN 停止成功 !" else echo -e "${Error} $NAME_BIN 停止失败 !" fi else echo -e "${Info} $NAME_BIN 未运行" RETVAL=1 fi fusermount -zuq $LOCAL >/dev/null 2>&1 fusermount -zuq $LOCAL1 >/dev/null 2>&1 } do_status(){ check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN (PID $(echo ${PID})) 正在运行..." else echo -e "${Info} $NAME_BIN 未运行 !" RETVAL=1 fi } do_restart(){ do_stop do_start } case "$1" in start|stop|restart|status) do_$1 ;; *) echo "使用方法: $0 { start | stop | restart | status }" RETVAL=1 ;; esac exit $RETVAL操作命令chmod +x /etc/init.d/rcloned /etc/init.d/rcloned start /etc/init.d/rcloned stop结语到这里就已经结束了,快来试一下世纪互联的极速吧。在这里推荐一家世纪互联:https://www.yiyi.one
2020年03月08日
6,454 阅读
0 评论
86 点赞
1
...
5
6