CODESHIF - 2018年10月 https://www.codeshif.com/2018/10/ 最有灵魂的开发者 Linux常用命令 https://www.codeshif.com/archives/16.html 2018-10-31T06:50:00+08:00 查看磁盘df -lfdisk -l命令历史dmesghistorycat /var/log/xxx.log修改su密码sudo passwd设置su可以ssh登录vi /etc/ssh/sshd_config将PermitRootLogin改为yes安装xfce4apt install xfce4 xfce4-goodiesapt install xfce-theme-managersu命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shell环境仍然是普通用户的Shell,环境变量没有变;而后者连用户和Shell环境一起切换成root身份了,且环境变量也变成了root用户下的环境变量。su切换成root用户以后,pwd一下,发现工作目录仍然是普通用户的工作目录;而用su -命令切换以后,工作目录变成root的工作目录了。https://www.cnblogs.com/xd502djj/p/6641475.html Mac下Charles iOS无法连接Charles,不弹窗口解决办法 https://www.codeshif.com/archives/15.html 2018-10-29T19:17:00+08:00 部分的路由器不知道设置了什么鬼东西,让你在同一WIFI下并不能正常连接Charles,所以开个个人热点吧!!你用一个手机开热点,然后把电脑连接到热点,iOS设备也连接到该热点,然后连接Charles的代理,瞬间弹窗了,我操。所以别相信什么路由器鬼东西,还是用热点比较靠谱,问题是……你得有两台手机,嘿嘿 菱形背景 https://www.codeshif.com/archives/14.html 2018-10-28T09:32:00+08:00 花瓣或堆糖或百度图片可以搜索菱形背景,会员背景图片,背景图像等,能找到很酷炫的例如1例如2例如 Atom Beautify插件无法格式化PHP代码及问题处理办法 https://www.codeshif.com/archives/13.html 2018-10-27T01:49:00+08:00 Atom Beautify需要一个php-cs-fixer的插件,安装该插件的方法,可以参照php-cs-fixer的安装方式安装,也可以使用brew install php-cs-fixer的方式安装。但是安装完毕使用的时候也许会有个错误?比如,我安装完成后对代码进行ctrl+alt+b就发现代码并没有格式化……为什么啊?原来是我的PHP代码出现了问题,所以在安装php-cs-fixer之前,还是先安装个linter-php吧,在Atom的Install搜索php就可以找到该选项了,安装就可以发现自己带代码有没有错误了。 Nginx反向代理NodeJS Express 强制HTTP跳转HTTPS https://www.codeshif.com/archives/12.html 2018-10-25T21:00:00+08:00 NodeJS推荐使用PM2进行管理状态,详情了解可以npm install pm2 -gpm2 --helppm2 examplespm2 start bin/www --name name --watch--watch是监视文件变化自动reload重点说说反向代理和跳转HTTPSUBUNTU系统,所以首先apt install nginx,然后进入/etc/nginx/sites-available里面新建一个网站配置,例如www.xxx.com,当然了你也可以复制现有default复制一份出来例如cp default www.xxx.com然后写入并以下信息 # 服务器的HTTP部分 server { listen 80; # 这里我直接做的反向代理,所以不用写根路径在哪 #root /var/www/html; # 强制从HTTP跳转到HTTPS rewrite ^(.*)$ https://$host$1 permanent; # 默认的网页名称 index index.html index.htm index.nginx-debian.html; # 网址名称 server_name xxx.net www.xxx.net; location / { # 这里就是反向代理的实现了,将访问的网址代理到本地NodeJS中 proxy_pass http://127.0.0.1:3000; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } # 服务器的HTTPS本分 server { listen 443; # 默认首页没啥好说的 index index.html index.htm index.nginx-debian.html; # 你的SSL信息,百度一下全是了 ssl on; ssl_certificate /etc/nginx/cert/215077960110430.pem; ssl_certificate_key /etc/nginx/cert/215077960110430.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; # HTTPS也要反向代理哦! location / { proxy_pass http://127.0.0.1:3000; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 哦了,代码就是这么简单,nginx -t检查一下配置有没有错,service nginx reload加载一下,刷新网页查看结果吧! NodeJS Express HTTP跳转HTTPS方法和错误解决 https://www.codeshif.com/archives/11.html 2018-10-22T21:23:00+08:00 NodeJS Express中写个中间件就可以搞定HTTP跳转HTTPS了,app.use(function (req, res, next) { if(req.protocol !== 'https'){ return res.redirect('https://' + req.hostname + req.originalUrl); } next(); });注意上面有个return可别忘写了,不然报错!Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:470:11) at ServerResponse.header (/root/taobao/node_modules/express/lib/response.js:767:10) at ServerResponse.send (/root/taobao/node_modules/express/lib/response.js:170:12) at done (/root/taobao/node_modules/express/lib/response.js:1004:10) at tryHandleCache (/root/taobao/node_modules/ejs/lib/ejs.js:257:5) at View.exports.renderFile [as engine] (/root/taobao/node_modules/ejs/lib/ejs.js:480:10) at View.render (/root/taobao/node_modules/express/lib/view.js:135:8) at tryRender (/root/taobao/node_modules/express/lib/application.js:640:10) at Function.render (/root/taobao/node_modules/express/lib/application.js:592:3) at ServerResponse.render (/root/taobao/node_modules/express/lib/response.js:1008:7)加上return就OK了 NodeJS request 复制PostMan代码 乱码 https://www.codeshif.com/archives/10.html 2018-10-21T03:23:00+08:00 在PostMan中,我们可以通过Chrome的Development-Tools工具复制由Network面板中的请求,复制的方式是Copy->CURL,就可以导入到PostMan里面了,但是PostMan可能复制出来的代码有问题,因为我使用的是NodeJS环境,所以我就遇到了乱码这个问题:var request = require("request"); var options = { method: 'GET', url: '', qs: { q: 'ios', code: 'utf-8', area: 'c2c', nick: '', sid: 'null' }, headers: { 'cache-control': 'no-cache', authority: '', accept: '*/*', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7,zh-TW;q=0.6', 'accept-encoding': 'gzip, deflate, br' } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); });乱码!怎么办呢?看似好像没什么问题,但是实际上是乱码的,God fuck my shit……最后我经历了很久的折磨之后,我其实以为是代码出了问题,其实不是,只是Chrome复制出来的东西,里面含有这个:'accept-encoding': 'gzip, deflate, br' 哈哈!是不是明白了,GZIP流压缩啊,当然会乱码,后来就明白了。真正的解决方法是:去掉这行就可以了'accept-encoding': 'gzip, deflate, br' OK! CSS3背景渐变颜色 https://www.codeshif.com/archives/6.html 2018-10-18T04:39:00+08:00 background-image: radial-gradient(circle farthest-side at right,#71c5ff,#ec92fd); background-image: radial-gradient(circle farthest-side at right,#ffc0c0,#ec92fd); background-image: radial-gradient(circle farthest-side at right,#cfc,#39c); background-image: radial-gradient(circle farthest-side at right,#9cc, #69c); background-image: radial-gradient(circle farthest-side at right,#ccf, #69c); background-image: radial-gradient(circle farthest-side at right,#ccf, #ccc); Typecho伪静态Rewrite设置 https://www.codeshif.com/archives/5.html 2018-10-18T01:38:00+08:00 在站点根目录写文件.htaccess文件,然后写入以下内容,并在设置中开启永久链接即可!<IfModule mod_rewrite.c> RewriteEngine On #如果开启了HTTPS服务,使用以下两行内容 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R=301] #开启伪静态 RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] &lt;/IfModule&gt; Typecho首页显示文章摘要的方法 https://www.codeshif.com/archives/4.html 2018-10-18T00:53:00+08:00 Typecho博客默认文章没有自动摘要的功能,首页和分类归档页面显示的文章都是全文输出的。不爽?那就登录到后台-控制台-外观-编辑当前外观:编辑文件 index.php找到:<?php $this->content('- 阅读剩余部分 -'); ?>替换成:<?php $this->excerpt(300,'- 阅读剩余部分 -'); ?>300这个数字,你怎么开心,怎么设置。还有个好方法:编辑文件/var/Widget/Abstract/Contents.php改成这样:/** * 输出文章摘要 * * @access public * @param integer $length 摘要截取长度 * @param string $trim 摘要后缀 */ public function excerpt($length = 100, $trim = '...') { // Typecho_Common::subStr(strip_tags($this->excerpt), 0, $length, $trim) echo Typecho_Common::subStr(strip_tags($this->excerpt), 0, $length, $trim) . "<p class=\"more\"><a href=\"{$this->permalink}\" title=\"{$this->title}\">- 阅读剩余部分 -</a></p>"; }