Rootop 服务器运维与web架构

2020-08-05
发表者 Venus
通过nginx debug日志查看location匹配已关闭评论

通过nginx debug日志查看location匹配

需要nginx编译时加上编译参数,如果没有的话就无法看到debug信息。

./configure --with-debug

参数才能启用debug日志。
然后在对应的虚拟主机配置

server
{
	略...
	location /
	{
		proxy_pass "http://127.0.0.1:8080";
	}

	location /login
	{
		proxy_pass "http://127.0.0.1:8080";
	}
		
	access_log logs/www.v.com_access.log;
	error_log  logs/www.v.com_error.log debug;
}

(win下的nginx可能支持debug)

浏览器访问: http://www.v.com/login

# 查看nginx中虚拟主机的error日志

[root@localhost logs]# tail -f www.v.com.error.log |grep -E "test location|using configuration"
2020/08/05 09:55:29 [debug] 14289#0: *2 test location: "/"
2020/08/05 09:55:29 [debug] 14289#0: *2 test location: "login"
2020/08/05 09:55:29 [debug] 14289#0: *2 using configuration "/login"

可以看到测试了2条location,最终匹配到了/login 部分。
这样在排查location匹配时就方便很多。

2020-07-22
发表者 Venus
http/1.1和http2中发起的tcp连接数比较已关闭评论

http/1.1和http2中发起的tcp连接数比较

谷歌浏览器对同一个 host(同一个域名,比如www.rootop.org)可以最多建立6个tcp连接。
不同的浏览器限制也不一样。
资料:https://developers.google.com/web/tools/chrome-devtools/network/issues#queued-or-stalled-requestsdevelopers.google.com
中描述了:
Too many requests are being made on a single domain. On HTTP/1.0 or HTTP/1.1 connections, Chrome allows a maximum of six simultaneous TCP connections per host.

在http/1.1版本协议中,请求头中包含 Connection: keep-alive 头信息,则为使用tcp连接复用。
这样页面中引用的js、css、图片等资源文件会在这6个tcp连接中传输(如果选择的连接中要有几十个资源,则串行传输)。
http2则可以并行传输。

# 通过 http 访问一个网站测试。
用wireshark抓包测试后,通过统计源端口号也确认了chrome发起了6个tcp连接。

# 本地发起连接的源端口号
wireshark过滤规则:

ip.dst==47.105.x.x and ip.src==192.168.1.145 and http.host==www.x.cn

统计后:
55660
55661
55662
55663
55664
55665

# nginx中配置https后,配置http2并抓包
wireshark过滤规则:

ip.dst==47.105.x.x and ip.src==192.168.1.145 and http2.headers.authority==www.x.com


发起的tcp连接源端口号只有一个,并且所有资源文件都在这个tcp连接中传输。

2020-07-22
发表者 Venus
wireshark解密https数据已关闭评论

wireshark解密https数据

# 首先设置一个系统环境变量

变量名:SSLKEYLOGFILE
变量值:D:\a\111

值的路径自定义,启动火狐浏览器,访问要解密的https网站,会自动生成 D:\a\111 这个文件。

# 配置wireshark
依次找到:
编辑 ->首选项 -> protocols -> tls
(Pre)-Master-Secret log filename 配置为上面的路径。


wireshark开始抓包,浏览器访问https站。
就可以看到解密的数据。

2020-07-15
发表者 Venus
centos中/etc/rc.local不执行问题已关闭评论

centos中/etc/rc.local不执行问题

帮忙排除一个/etc/rc.local开机不执行的问题。系统是centos6

首先也是考虑权限的问题,设置了777权限也不可以。
最后发现/etc/rc.local成了一个文件,而不是软链接,正常情况是软链接到/etc/rc.d/rc.local文件。
/etc/rc.d/rc.local文件才是开机执行的脚本,/etc/rc.local推测只是为了方便编辑才设置的软链接。
所以导致/etc/rc.local种的配置并没有实际生效,因为/etc/rc.d/rc.local并没有被修改。

[root@localhost ~]# ll /etc/rc.local 
lrwxrwxrwx 1 root root 18 Jul 15 10:07 /etc/rc.local -> /etc/rc.d/rc.local

从下面的启动流程图可以看出实际的执行脚本为/etc/rc.d/rc.local

2020-07-14
发表者 Venus
sed 修改分隔符已关闭评论

sed 修改分隔符

字符串 a/b/c/def
比如要替换字符串 a/b/c 为aaa

# 未加转义符

[root@localhost ~]# sed -i 's/a/b/c/aaa/g' test.txt
sed: -e expression #1, char 7: unknown option to `s'

不加转义则报错

# 加转义

[root@localhost ~]# sed -i 's/a\/b\/c/aaa/g' test.txt
[root@localhost ~]# cat test.txt
aaa/def

# 加转义符不美观,可以换个分隔符来实现

[root@localhost ~]# cat test.txt
a/b/c/def
[root@localhost ~]# sed -i 's#a/b/c#aaa#g' test.txt
[root@localhost ~]# cat test.txt
aaa/def