深入浅出Node.JS 读书笔记

2018-2-12

1.书里一直在说I/O,我就很想知道具体的定义是读写还是网络请求处理。搜了一圈,都是在讲异步I/O,阻塞,非阻塞什么的。还好Node的官网有说。

“I/O” refers primarily to interaction with the system’s disk and network supported by libuv.

https://nodejs.org/en/docs/guides/blocking-vs-non-blocking/

libuv定义的I/O是说,系统的数据读写和网络支持交互。

Nginx反向代理Nodejs服务通过SSL证书实现微信小程序Post

安装Nginx,Nodejs 安装过程

启动Nodejs服务。express 或者别的什么后台服务

比如启动以后的服务地址 localhost:3000

配置Nginx

/etc/nginx/nginx.conf

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
	listen	443 ssl;
	ssl_certificate  /etc/nginx/ssl/xxxx.crt;        #你的CRT
	ssl_certificate_key /etc/nginx/ssl/xxxx.key; #你的Key
	server_name xxx.com;                                   #域名
	ssl_session_cache shared:SSL:1m;
    	ssl_session_timeout 5m;
    	ssl_protocols SSLv3 TLSv1;
        root         /usr/share/nginx/html;

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

        location / {
		proxy_pass http://127.0.0.1:3000;        #Node的服务
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_set_header Host $host;
        	proxy_set_header X-Forward-Proto https;
        	proxy_http_version 1.1;
        	# for websocket
        	proxy_set_header Upgrade $http_upgrade;
        	proxy_set_header Connection "upgrade";
        }

然后重启Nginx
sudo systemctl restart nginx

在小程序里Post
wx.request({
url: “https://xxx.com:443/posts”,
…….
OK~

PS:上面是腾讯云的设置,阿里云的略有所不同。