CentOS 7无法为nginx自动续期Let’s Encript证书的解决办法

使用crontab来自动为nginx续期证书,但一直失败,命令为:

certbot --nginx renew

在 /var/log/letsencrypt/ 下的日志文件显示:
Could not find a usable ‘nginx’ binary

可能是在PATH中未找到nginx可执行程序,可以手动指定,最终命令如下:

certbot --nginx --nginx-ctl /usr/sbin/nginx renew

参考资料:
https://community.letsencrypt.org/t/certbot-cron-job-nginx-plugin-noinstallationerror/67572

Chrome 69+地址栏显示完整URL

Chrome 69-70

  • 打开chrome://flags/
  • 搜索Omnibox UI Hide Steady-State URL Scheme and Trivial Subdomains,设置为Disabled
  • 重启浏览器

Chrome 71-78

  • 打开chrome://flags/
  • 搜索Omnibox UI Hide Steady-State URL,将结果项全部设置为Disabled
  • 重启浏览器

Chrome 79+

安装名为Suspicious Site Reporter的扩展。

使用rewrite重定向http到https

Apache httpd

RewriteEngine On
# RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301,NE,QSA]

如Server绑定多个域名,需要针对实际请求的主机名重定向,可以把%{SERVER_NAME}替换成%{HTTP_HOST}

Nginx

rewrite ^ https://$host$request_uri permanent;

也可以直接使用return语句

return 301 https://$host$request_uri;

JavaScript中Object和Function及其prototype之间的关系

引子

在nodejs中执行如下代码

> Object instanceof Function
true

> Function.prototype instanceof Object
true

> Function instanceof Function
true

是不是有点迷惑?

instanceof的真实含义

在js中判断某个实例是否某个类的实例,我们可以是用如下代码:

function Test() {}
var t = new Test();
t instanceof Test;  // true

从字面上看,要表达的意思很直接。然而让我们hack一下代码,看看会发生什么:

var testPrototype = Test.prototype;
Test.prototype = {};
t instanceof Test;  // false

当Test类的原型更新为另一个对象时,之前用Test创建的实例其原型不变,依旧是Test上原先的prototype。从这个例子可以看出,我们可以大致这么理解instanceof这个语法:

t inheritsFrom Test.prototype

为了获得或判断t的真实原型,ES5提供了Object.getPrototypeOf()和Object.prototype.isPrototypeOf()方法:

Object.getPrototypeOf(t) === testPrototype;  // true
testPrototype.isPrototypeOf(t);  // true

构造函数只是实例和原型的连接器

当使用构造函数创建对象后,对象与其原型已经联系起来,之后构造函数对于这两者已经没有什么存在的意义了。我们用猎头撮合人才与公司签订劳动协议来举例子:

          劳动协议签订完毕
人才 --------------------------> 公司

       猎头:没我什么事儿了……

这个法则也适用于js对象的原型继承:

            继承关系建立
实例 --------------------------> 原型

       构造函数:没我什么事儿了……

构造函数就像中介,用来联系实例和原型。构造函数和原型虽然有prototype属性联系,但他们真的没什么大关系。

整理混乱的关系

在js中不污染prototype时具有以下规则:
– 所有function都继承自Function.prototype
– Object构造函数也是function,因此也继承自Function.prototype
– Function构造函数也是function,因此也继承自Function.prototype
– Function.prototype继承自Object.prototype,但增加了callable的支持,即可以在标识符后边使用()来触发调用

继承关系图

Object.prototype
        ^
        |
Function.prototype
    ^        ^
    |        |
 Object   Function

验证代码:

> Object.getPrototypeOf(Object.prototype) === null
true

> Object.getPrototypeOf(Function.prototype) === Object.prototype
true

> Object.getPrototypeOf(Object) === Function.prototype
true

> Object.getPrototypeOf(Function) === Function.prototype
true

在有CSS transform属性的元素内position fixed定位错误的解释

当容器元素具有CSS transform定义时,会隐式地生成定位容器,transform容器及其子元素都会相对于该隐式容器做transform变换,即便内部元素具有position:fixed也无法逃脱,其行为就好像设置了position:absolute,详见参考资料。

参考资料

https://stackoverflow.com/questions/9115880/css-transform-translate-moves-postionfixed-inner-div

https://meyerweb.com/eric/thoughts/2011/09/12/un-fixing-fixed-elements-with-css-transforms/

更改systemd服务同时打开的文件数

更改ulimit配置文件是不起作用的,需要修改service单元文件:

[Service]
LimitNOFILE=8192

有效的Limit选项可以运行man 5 systemd.exec查看。

  LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=,
       LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=,
       LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=,
       LimitRTTIME=
           These settings control various resource limits for executed
           processes. See setrlimit(2) for details. Use the string infinity to
           configure no limit on a specific resource.

参考资料:

https://serverfault.com/questions/649577/how-can-i-permanently-set-ulimit-n-8192-in-centos-7#answer-720596

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files#sect-Managing_Services_with_systemd-Unit_File_Create

https://access.redhat.com/solutions/1257953