快速删除 node_modules 文件夹

系统命令

# cmd
# /q 直接删除,不需要二次确认
# /s 允许删除非空目录
rd /q/s node_modules

# powershell
rmdir -r -Force node_modules
# 或
rm -r -Force node_modules

使用 npm 包

npm i rimraf -g
rimraf node_modules

npm i -g dlf
dlf node_modules

一次执行多条命令

# cmd 使用 && 连接多个命令
cd vue && npm i
# powershell 使用 | 连接多条命令
cd vue | npm i

删除一个文件夹内字节小于 10kb 的文件

# 输出所有大小小于10k的文件
# find ./ -size -10k > NoNeedSite.txt
find ./ -size -10k -exec rm {} \

Window.history 是一个只读属性,提供了操作浏览器会话历史(浏览器地址栏中访问的页面,以及当前页面中通过框架加载的页面)的接口。HTML5 引入了 history.pushState() 和 history.replaceState() 方法,它们分别可以添加和修改历史记录条目。这些方法通常与 window.onpopstate 配合使用。

参考

https://developer.mozilla.org/zh-CN/docs/Web/API/History_API

https://developer.mozilla.org/zh-CN/docs/Web/API/Window/history

在 history 中跳转

window.history.back() // 向后跳转 相当于点击浏览器回退按钮
window.history.forward() // 向前跳转 相当于点击了前进按钮
window.history.go(-1) // 跳转 历史中的某一特定页面(go(-1) 等同于调用 back())

可以通过查看长度属性的值来确定的历史堆栈中页面的数量

window.history.length
history.pushState(stateObject, title, url)

状态对象(stateObject)–stateObject 是一个 JavaScript 对象,通过 pushState 方法可以将 stateObject 内容传递到新页面中。

标题(title)–几乎没有浏览器支持该参数,但是传一个空字符串会比较安全。

地址(url)–新的历史记录条目的地址(可选,不指定的话则为文档当前 URL);浏览器在调用 pushState()方法后不会加载该地址;传入的 URL 与当前 URL 应该是同源的,否则,pushState()会抛出异常。

history.pushState()主要是在不刷新浏览器的情况下,创建新的浏览记录并插入浏览记录队列中

假设在 http://mozilla.org/foo.html 中执行了以下 JavaScript 代码:

let stateObj = {
foo: 'bar'
}
history.pushState(stateObj, 'page 2', 'bar.html')

这将使浏览器地址栏显示为 http://mozilla.org/bar.html,但并不会导致浏览器加载 bar.html ,甚至不会检查 bar.html 是否存在

history.replaceState() 的使用与 history.pushState() 非常相似,区别在于 replaceState() 是修改了当前的历史记录项而不是新建一个

Apache 安装

centos

# yum install httpd  (centos之下,Apache的名字叫httpd,和Apache的主程序 httpd.exe 同名)

打开并测试 Apache

  • 先确保,云服务器的 80 端口,是允许外网访问的。

  • 开启 Apache 服务

service httpd start
# 查看状态
service httpd status
  • 测试 Apache 是否正常运行

浏览器输入: 外网 IP:80,如果能正常显示 Apache 的内置主页,则说明 Apache 服务已正常开启。

修改 Apache 的配置文件

主配置文件 /etc/httpd/conf/httpd.conf

修改如下键值兼容 php

键:DirectoryIndex
值:index.html index.php

默认站点主目录:/var/www/html/

https://www.cnblogs.com/smbin/p/6946210.html

安装证书

  1. 安装 ssl 模块
# yum install mod_ssl -y

Ps:安装完成后,会在/etc/httpd/conf.d/下生成一个 ssl.conf 配置文件。

建一个目录用来放 ssl 证书文件

# mkdir /etc/httpd/ssl/

编辑 ssl 配置文件

# vim /etc/httpd/conf.d/ssl.conf

修改以下几行,去掉前面的“#”注释;

<VirtualHost>
#网页文件路径
DocumentRoot "/var/www/html"
#改为自己的域名
ServerName cuilongjin.top:80
#启用SSL功能
SSLEngine on
#填写证书文件路径
SSLCertificateFile /etc/httpd/ssl/cert-1541656252121_cuilongjin.top.key
#填写私钥文件路径
SSLCertificateKeyFile /etc/httpd/ssl/cert-1541656252121_cuilongjin.top.key
#填写证书链文件路径
SSLCertificateChainFile /etc/httpd/ssl/cert-1541656252121_cuilongjin.top_chain.crt
</VirtualHost>

重启服务器

# service httpd restart

Nginx 的安装与配置

CentOS 下安装:

通过安装包安装

# 安装所需环境
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

# 官网下载 nginx https://nginx.org/
yum install wget
wget -c https://nginx.org/download/nginx-1.17.4.tar.gz
# 解压
tar -zxvf nginx-1.17.4.tar.gz
cd nginx-1.17.1

# 配置
./configure

# 编译安装
make
make install

# 查找安装路径:
whereis nginx

# 启动、停止 重启 nginx
cd /usr/local/nginx/sbin/
./nginx # 启动
./nginx -s stop # 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit # 此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s quit && ./nginx # 重启 nginx

# 重新加载配置文件
# 配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用 -s reload 不用先停止 nginx 再启动即可将配置信息在 nginx 中生效,如下:
./nginx -s reload

# 查询 nginx 进程
ps aux|grep nginx

# 开机自启动
在 rc.local 增加启动代码
vi /etc/rc.local
# 增加一行 /usr/local/nginx/sbin/nginx
# 设置执行权限
chmod 755 rc.local

# 添加 nginx 为系统服务

centos 下,yum 源不提供 nginx 的安装,可以通过切换 yum 源的方法获取安装

yum -y install nginx

主站点目录/usr/share/nginx/html

配置 Nginx:

Nginx 的配置文件默认位置为:/etc/nginx/nginx.conf

server {
listen 80; #监听80端口,接收http请求
server_name localhost; #就是网站地址
root /usr/share/nginx/html; # 准备存放代码工程的路径
#路由到网站根目录www.example.com时候的处理
location / {
index index.php index.html index.htm;
}

#当请求网站下php文件的时候,反向代理到php-fpm
location ~ \.php$ {
include fastcgi.conf; #加载nginx的fastcgi模块
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000; #nginx fastcgi进程监听的IP地址和端口
}
}

自定义 Nginx 站点配置文件存放目录

/etc/nginx/conf.d/

默认站点目录/usr/share/nginx/html

安装 php

yum install php php-fpm

配置 php.ini

/etc/php.ini

cgi.fix_pathinfo=1

配置 php-fpm

/etc/php-fpm.d/www.conf

user = nginx

group = nginx

chkconfig php-fpm on #设置 php-fpm 自启动

service nginx restart #重新启动 nginx

service php-fpm start #启动 php-fpm

sudo iptables -I INPUT -p tcp -m tcp –dport 80 -j ACCEPT

sudo iptables -I INPUT -p tcp -m tcp –dport 443 -j ACCEPT

iptables -L -n

/usr/sbin/nginx

查询 nginx 进程

ps -ef | grep nginx

nginx 配置

#
# HTTPS server configuration
#

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl;
server_name _;
root /usr/share/nginx/html;

ssl_certificate ssl/cuilongjin.top.pem;
ssl_certificate_key ssl/cuilongjin.top.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
#
# The default server
#

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

ubuntu 下安装

安装 nginx

sudo apt-get install nginx

Ubuntu 安装之后的文件结构大致为:

  • 所有的配置文件都在/etc/nginx 下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available 下
  • 程序文件在/usr/sbin/nginx
  • 日志文件在/var/log/nginx
  • 并已经在/etc/init.d/下创建了启动脚本 nginx
  • 服务器配置文件在/etc/nginx/sites-available/
  • 默认主站点目录 /var/www/html,(有的可能在/var/www), 请参考/etc/nginx/sites-available 里的配置

安装 php

apt-get install php

配置 php.ini /etc/php/7.2/cli/

cgi.fix_pathinfo=1

配置 php-fpm

启动 nginx

/etc/init.d/nginx restart
/etc/init.d/nginx stop
/etc/init.d/nginx start

删除 nginx

sudo apt-get --purge remove nginx
# –-purge 包括配置文件

arch 下安装 nginx

pacman -S nginx

启动 Nginx 服务,运行以下命令:

# systemctl start nginx

要 Nginx 服务开机时启动,运行以下命令:

# systemctl enable nginx

默认页面是:

/usr/share/nginx/html/index.html

配置

你可以修改在 /etc/nginx/ 目录中的文件来更改配置 ./etc/nginx/nginx.conf 是主配置文件

移动端(Safari)浏览网页时对数字禁用电话功能

  • 标准的电话号码格式是:
<a href="tel:+86-123-456-7890">1234567890</a>
  • 有时候不是电话号码的数字会被浏览器自动解析为如上电话号码格式,导致样式和布局改变

  • 忽略页面中的数字识别为电话号码, 只要把这个默认行为关闭就行

<meta name="format-detection" content="telephone=no" />
  • 这个关闭不会影响真正电话号码的识别

说明:Meta 标签中的 format-detection 属性及含义
format-detection 中文的意思是 “格式检测”,它是用来检测 html 里的一些格式的

<!-- 禁止了把数字转化为拨号链接 默认为 yes -->
<meta name="format-detection" content="telephone=no" />
<!-- 禁止作为邮箱地址 默认为 yes -->
<meta name="format-detection" content="email=no" />
<!-- 禁止跳转至地图 默认为 yes -->
<meta name="format-detection" content="adress=no" />
<meta name="format-detection" content="telephone=no,email=no,adress=no" />

在网上搜索后发现有可能有以下原因:

1.你的 VPS 被人用来做爬虫爬 Google,IP 被封

2.你的 IPv4 网段有人做爬虫,网段被封

3.你的 IPv6 网段有人做爬虫,网段被封

IPv6 网段被封

强制你的 VPS 用 IPv4 来访问,具体方法在 /etc/sysctl.conf 后追加

# disable ipv6
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

IPv4 网段被封

强制 VPS 使用 IPv6 访问,确认打开 VPS 上的 IPv6 功能,更改 VPS 的 hosts 中指定 Google Schoolar 的 IPv6 地址,编辑/etc/hosts后追加:

## Scholar
## type 'host google.com' to get the correct ipv6 address or
## visit https://github.com/lennylxx/ipv6-hosts
2404:6800:4004:81a::200e scholar.google.cn
2404:6800:4004:81a::200e scholar.google.com.hk
2404:6800:4004:81a::200e scholar.google.com
2404:6800:4004:81a::200e scholar.l.google.com

更改配置后,重启 SS

购买 VPS 服务器

vultr 注册地址:https://www.vultr.com/

利用 ipip 这个网站的 实用工具里的 ping 来全国性的 ping 我们的主机,检测连通性

部署 VPS 服务器

ssh 工具

Win:
使用软件 PuTTY
打开软件
Host Name (or IP address) 写你服务器的 IP 地址
Port 默认 22
Connection type 选择 SSH
Open

Mac:
默认有 SSH 命令
ssh root@IP
输入用户名和密码,用户名为 root
login as: root
root@IP’s password:

安装服务

CentOS/Debian/Ubuntu ShadowsocksR 单/多端口 一键管理脚本
https://doub.io/ss-jc42/

yum -y install wget

wget -N --no-check-certificate https://softs.fun/Bash/ssr.sh && chmod +x ssr.sh && bash ssr.sh

备用脚本:

yum -y install wget

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh && chmod +x ssr.sh && bash ssr.sh

复制上面的代码到 VPS 服务器里,按回车键,脚本会自动安装,以后只需要运行 bash ssr.sh 这个快捷命令就可以出现下图的界面进行设置。

  1. 安装 SSR 服务端
  2. 设置端口和密码
  3. 设置的加密方式: aes-256-cfb
  4. 选择协议插件: auth_sha1_v4
  5. 选择混淆插件 plain

ShadowsocksR MudbJSON 模式多用户一键脚本 支持流量限制
https://doub.io/ss-jc60/

wget -N --no-check-certificate https://softs.fun/Bash/ssrmu.sh && chmod +x ssrmu.sh && bash ssrmu.sh

备用下载地址

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssrmu.sh && chmod +x ssrmu.sh && bash ssrmu.sh
bash ssrmu.sh

测速脚本官方地址

wget https://raw.githubusercontent.com/oooldking/script/master/superbench.sh
chmod +x superbench.sh
./superbench.sh

加速

锐速/BBR/魔改 BBR/KCPTUN 加速效果对比测试

【原版 BBR】

wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
chmod +x bbr.sh
./bbr.sh

# 重启服务器

# 验证是否安装成功
sysctl net.ipv4.tcp_congestion_control
# 得到如下结果表示安装成功
net.ipv4.tcp_congestion_control = bbr

【魔改 BBR】

只有 centos 和 debain 版

# centos 版
wget --no-check-certificate https://raw.githubusercontent.com/tcp-nanqinlang/general/master/General/CentOS/bash/tcp_nanqinlang-1.3.2.sh
bash tcp_nanqinlang-1.3.2.sh

# debain 版
wget --no-check-certificate https://github.com/tcp-nanqinlang/general/releases/download/3.4.2.1/tcp_nanqinlang-fool-1.3.0.sh
bash tcp_nanqinlang-fool-1.3.0.sh

# 选择 1 安装内核,重启

# 运行 选择 2 安装并开启算法
bash tcp_nanqinlang-1.3.2.sh
# 选择 2 安装并开启算法

【BBRPlus(BBR v2.0)】

Github 项目地址:https://github.com/cx9208/bbrplus

一键脚本(仅CentOS)

yum -y install wget && wget "https://github.com/cx9208/bbrplus/raw/master/ok_bbrplus_centos.sh" && chmod +x ok_bbrplus_centos.sh && ./ok_bbrplus_centos.sh

等待安装完成,重启,重启之后,按照以下步骤检查是否成功:

执行 uname -r,显示 4.14.129-bbrplus 则切换内核成功

执行 lsmod | grep bbr,显示有 bbrplus 则开启成功

解决某些 npm 包无法下载的问题

如 electron sass

修改 ~/.npmrc,或当前项目下的.npmrc 文件(如果没有可以新建)增加如下内容

registry=https://registry.npm.taobao.org
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs
electron_mirror=http://npm.taobao.org/mirrors/electron/
chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver

淘宝 npm 镜像 https://npm.taobao.org/

npm 官网
npm 文档
npm 中文文档

npm 基本命令

# 更新 npm
npm -v|--version
npm install npm@latest -g

# nvm : npm Version Manager

# 搜索包
npm search <pkg>

# 安装包
npm install [<@scope>/]<pkg> # [<@scope>/] 安装限定范围的包
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <folder>
npm install <tarball file> # .tar, .tar.gz, or .tgz
npm install <tarball url>

# 公有仓库
npm install user/project # 默认 github
npm install bitbucket:user/project
npm install gitlab:user/project#semver:^5.0 # semver 版本
npm install git+https://git@github.com/user/project.git
npm install git+ssh://git@github.com/user/project.git
npm install git://github.com/user/project.git


npm install <pkg> -S|--save # 安装到 dependencies
npm install <pkg> -D|--save-dev # 安装到 devDependencies

# --verbose 参数 显示安装的详细信息
npm i --verbose

# --production 参数 只会安装 dependencies 依赖,而忽略 devDependencies 依赖,用于生产环境
npm i --production

# 安装全局包
npm install -g <pkg>

# 更新包
npm outdated # 检查可以更新的模块
npm update # 更新全部本地包
# 更新全局安装的包
npm update -g # 更新全部
npm update -g| --global <pkg> # 更新指定包

# 更新方式 1
# 手动修改 package.json 中依赖包版本,之后执行
npm install --force

# 更新方式 2 使用第三方插件:
npm install -g npm-check-updates
ncu # 查看可更新包
ncu -u # 更新 package.json
npm install # 升级到最新版本

# 删除本地包
npm uninstall <pkg>
npm uninstall --save <pkg> # 从 `package.json` 文件中删除依赖

# 卸载全局安装的包
npm uninstall -g <pkg>

# 打开官网
npm docs|home [<pkg>]
# 打开源码仓库页面
npm repo [<pkg>]

# 初始化一个项目,创建一个 package.json 文件,项目名不能为中文
npm init
# 创建默认 package.json 文件 快速的初始化一个项目,会使用文件夹名称作为项目名
npm init --yes or -y

简写

npm install  可简写成 npm i

npm uninstall 可简写成 npm uni

npm 修改源

修改全局配置

  • 进入~/.npmrc 增加 registry=https://registry.npm.taobao.org
  • 通过命令 npm config set registry https://registry.npm.taobao.org

修改当前项目的 npm 源

package.json 同级目录下创建 .npmrc 文件,增加 registry=https://registry.npm.taobao.org

临时使用指定源下载 npm install jquery --registry=https://registry.npm.taobao.org

使用 nrm 管理源

npm 配置文件

# .npmrc 配置文件位置(~/.npmrc)
npm config list

# npm 缓存目录,默认 C:\Users\<username>\AppData\Roaming\npm-cache
npm config get cache

# 删除 npm 缓存:注意:如果网速慢的话,会导致下载失败。 再重新下载之前,建议使用该命令,清除刚才下载的缓存,否则有可能一直无法下载成功
npm cache clean --force | -f

# npm 全局 node 包位置: 默认在 C:\Users\用户名\AppData\Roaming\npm目录下
npm config get prefix
# 或者
npm root -g

# 修改 npm 全局文件位置及缓存文件位置
npm config set prefix "<new_path>"
npm config set cache "<new_path>"

版本号

使用 NPM 下载和发布代码时都会接触到版本号。NPM 使用语义版本号来管理代码

语义版本号分为 X.Y.Z 三位,分别代表主版本号、次版本号和补丁版本号。当代码变更时,版本号按以下原则更新。

  • 如果只是修复 bug,需要更新 Z 位
  • 如果是新增了功能,但是向下兼容,需要更新 Y 位
  • 如果有大变动,向下不兼容,需要更新 X 位

nrm 使用

nrm:npm registry manager(npm 仓库地址管理工具)

# 查看配置列表,带 `*` 号即为当前使用的配置
nrm ls

# 切换源
nrm use 源的别名

# 添加源
nrm add 别名 地址

# 测速
nrm test 别名

# 删除源
nrm del 别名

查看项目安装了那些包

npm list --depth=0 [--dev | --production]
npm list --depth=0

–depth 表示深度,我们使用的模块会有依赖,深度为零的时候,不会显示依赖模块

查看全局安装的包

npm list --depth=0 --global

package.json 文件

package.json 文件,包(项目)描述文件,用来管理组织一个包(项目),它是一个纯 JSON 格式的

  • 作用:描述当前项目(包)的信息,描述当前包(项目)的依赖项
  • 如何生成:npm init或者npm init -y
  • 作用
    • 作为一个标准的包,必须要有package.json文件进行描述
    • 一个项目的 node_modules 目录通常都会很大,不用拷贝 node_modules 目录,可以通过 package.json 文件配合npm install 直接安装项目所有的依赖项
  • 描述内容
{
"name": "myproject", // 描述了包的名字,不能有中文
"version": "1.0.0",
"description": "", // 包的描述信息
"main": "index.js", // 入口文件
"scripts": {
// 配置一些脚本
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [], // 关键字(方便搜索)
"author": "", // 作者信息
"license": "ISC", // 许可证,开源协议
"dependencies": {
// 项目依赖
"bootstrap": "^3.3.7",
"jquery": "^3.3.1"
}
}

注意:一个合法的 package.json,必须要有 name 和 version 两个属性

http://www.asciiworld.com/
https://github.com/Blankj/awesome-comment

 -------------------------
< Just have fun with gist >
-------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
//When I wrote this, only God and I understood what I was doing
//Now, God only knows