CODESHIF - 2018年10月 http://codeshif.com/2018/10/ zh-CN 最有灵魂的开发者 Wed, 31 Oct 2018 06:50:00 +0800 Wed, 31 Oct 2018 06:50:00 +0800 Linux常用命令 http://codeshif.com/archives/16.html http://codeshif.com/archives/16.html Wed, 31 Oct 2018 06:50:00 +0800 admin 查看磁盘
df -l
fdisk -l

命令历史
dmesg
history
cat /var/log/xxx.log

修改su密码
sudo passwd

设置su可以ssh登录
vi /etc/ssh/sshd_config
PermitRootLogin改为yes

安装xfce4
apt install xfce4 xfce4-goodies
apt install xfce-theme-manager

su命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shell环境仍然是普通用户的Shell,环境变量没有变;而后者连用户和Shell环境一起切换成root身份了,且环境变量也变成了root用户下的环境变量。su切换成root用户以后,pwd一下,发现工作目录仍然是普通用户的工作目录;而用su -命令切换以后,工作目录变成root的工作目录了。

https://www.cnblogs.com/xd502djj/p/6641475.html

]]>
0 http://codeshif.com/archives/16.html#comments http://codeshif.com/feed/2018/10/
Mac下Charles iOS无法连接Charles,不弹窗口解决办法 http://codeshif.com/archives/15.html http://codeshif.com/archives/15.html Mon, 29 Oct 2018 19:17:00 +0800 admin 部分的路由器不知道设置了什么鬼东西,让你在同一WIFI下并不能正常连接Charles,所以开个个人热点吧!!
你用一个手机开热点,然后把电脑连接到热点,iOS设备也连接到该热点,然后连接Charles的代理,瞬间弹窗了,我操。

所以别相信什么路由器鬼东西,还是用热点比较靠谱,问题是……你得有两台手机,嘿嘿

]]>
0 http://codeshif.com/archives/15.html#comments http://codeshif.com/feed/2018/10/
菱形背景 http://codeshif.com/archives/14.html http://codeshif.com/archives/14.html Sun, 28 Oct 2018 09:32:00 +0800 admin 花瓣或堆糖或百度图片可以搜索菱形背景会员背景图片背景图像等,能找到很酷炫的

例如1
例如2
例如

]]>
0 http://codeshif.com/archives/14.html#comments http://codeshif.com/feed/2018/10/
Atom Beautify插件无法格式化PHP代码及问题处理办法 http://codeshif.com/archives/13.html http://codeshif.com/archives/13.html Sat, 27 Oct 2018 01:49:00 +0800 admin Atom Beautify需要一个php-cs-fixer的插件,
安装该插件的方法,可以参照php-cs-fixer的安装方式安装,
也可以使用brew install php-cs-fixer的方式安装。

但是安装完毕使用的时候也许会有个错误?
比如,我安装完成后对代码进行ctrl+alt+b就发现代码并没有格式化……

为什么啊?原来是我的PHP代码出现了问题,所以在安装php-cs-fixer之前,还是先安装个linter-php吧,
AtomInstall搜索php就可以找到该选项了,安装就可以发现自己带代码有没有错误了。

]]>
0 http://codeshif.com/archives/13.html#comments http://codeshif.com/feed/2018/10/
Nginx反向代理NodeJS Express 强制HTTP跳转HTTPS http://codeshif.com/archives/12.html http://codeshif.com/archives/12.html Thu, 25 Oct 2018 21:00:00 +0800 admin NodeJS推荐使用PM2进行管理状态,详情了解可以
npm install pm2 -g
pm2 --help
pm2 examples

pm2 start bin/www --name name --watch
--watch是监视文件变化自动reload

重点说说反向代理和跳转HTTPS

UBUNTU系统,所以首先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加载一下,刷新网页查看结果吧!

]]>
0 http://codeshif.com/archives/12.html#comments http://codeshif.com/feed/2018/10/
NodeJS Express HTTP跳转HTTPS方法和错误解决 http://codeshif.com/archives/11.html http://codeshif.com/archives/11.html Mon, 22 Oct 2018 21:23:00 +0800 admin 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了

]]>
0 http://codeshif.com/archives/11.html#comments http://codeshif.com/feed/2018/10/
NodeJS request 复制PostMan代码 乱码 http://codeshif.com/archives/10.html http://codeshif.com/archives/10.html Sun, 21 Oct 2018 03:23:00 +0800 admin PostMan中,我们可以通过ChromeDevelopment-Tools工具复制由Network面板中的请求,

屏幕快照 2018-10-21 上午3.17.18.png

复制的方式是Copy->CURL,就可以导入到PostMan里面了,

屏幕快照 2018-10-21 上午3.18.17.png

但是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);
});

乱码!

屏幕快照 2018-10-21 上午3.16.03.png

怎么办呢?
看似好像没什么问题,但是实际上是乱码的,God fuck my shit……

最后我经历了很久的折磨之后,我其实以为是代码出了问题,其实不是,只是Chrome复制出来的东西,里面含有这个:

'accept-encoding': 'gzip, deflate, br' 

哈哈!是不是明白了,GZIP流压缩啊,当然会乱码,后来就明白了。

真正的解决方法是:去掉这行就可以了

'accept-encoding': 'gzip, deflate, br'

OK!

]]>
0 http://codeshif.com/archives/10.html#comments http://codeshif.com/feed/2018/10/
CSS3背景渐变颜色 http://codeshif.com/archives/6.html http://codeshif.com/archives/6.html Thu, 18 Oct 2018 04:39:00 +0800 admin 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); ]]> 0 http://codeshif.com/archives/6.html#comments http://codeshif.com/feed/2018/10/ Typecho伪静态Rewrite设置 http://codeshif.com/archives/5.html http://codeshif.com/archives/5.html Thu, 18 Oct 2018 01:38:00 +0800 admin 在站点根目录写文件.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;
]]>
0 http://codeshif.com/archives/5.html#comments http://codeshif.com/feed/2018/10/
Typecho首页显示文章摘要的方法 http://codeshif.com/archives/4.html http://codeshif.com/archives/4.html Thu, 18 Oct 2018 00:53:00 +0800 admin 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>";
    }
]]>
0 http://codeshif.com/archives/4.html#comments http://codeshif.com/feed/2018/10/