kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

php ci 数据缓存

https://blog.csdn.net/weixin_30289299/article/details/115545367

CI框架中有个比较好的查询优化,就是数据库缓存优化

1.开启缓存

在application/config.php中开启

1
$db['default']['cache_on'] = TRUE;

在application/config.php中开启

1
$db['default']['cachedir'] = './cache';

并在对应的目录中加一个可写缓存目录cache

2. 在对应的查询中开启缓存语句

打开缓存开关

1
2
3
$this->db->cache_on();

$query = $this->db->query("SELECT * FROM mytable");

使下面这条查询不被缓存

1
2
3
4
5
6
7
8
9
$this->db->cache_off();

$query = $this->db->query("SELECT * FROM members WHERE member_id = '$current_user'");

// Turn caching back on

$this->db->cache_on();

$query = $this->db->query("SELECT * FROM another_table");

3. 添加相应的 清空缓存

缓存不会自动删除 只能手动删除

这样 你可以在对应的 增改删 语句中清除缓存 就ok了

清空所有缓存

1
$this->db->cache_delete_all()
清空单个缓存

example.com/index.php/blog/comments的页面, 缓存系统会把所有生成的缓存文件放进

一个以 blog+comments做为名称的文件夹里. 如果您要删除关于刚才提到的这个例子与

之对应的缓存文件 需要执行以下代码:

1
$this->db->cache_delete('/blog', 'comments');

nginx配置多个域名, http https共用配置

https://www.cnblogs.com/dayq/p/17488471.html

0. user

1
2
3
4
5
groupadd nginx
useradd nginx -g nginx

mkdir /var/www/nginx
chown -R nginx:nginx /var/log/nginx/*

1. nginx

vim /usr/local/openresty/nginx/conf/nginx.conf

域名 s1.com *.s1.com 建议分开写两个?

如果需要多个域名共用端口则复制多个

增加回源地址 Proxy: “$proxy_host” “$upstream_addr”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

......

http {
	log_format  main  '$fmt_localtime $request_time $server_addr $server_port $remote_addr $remote_port $status $body_bytes_sent $request_method $server_protocol'
			  ' "$host" "$uri" "$query_string" "$http_referer" "$http_user_agent" "$ssl_protocol" "$ssl_cipher" "-" "$remote_user" "$http_x_forwarded_for"'
			  ' Proxy: $upstream_response_time $proxy_host $upstream_addr $upstream_status $upstream_response_length';
	access_log  /var/log/nginx/access.log  main;

	map $host $fmt_localtime {
		default '';
	}
	log_by_lua_block {
		ngx.var.fmt_localtime = ngx.localtime();
	}

	sendfile      on;
	tcp_nopush        on;
	tcp_nodelay       on;
	keepalive_timeout 65;
	types_hash_max_size   4096;
	#gzip  on;


	include       mime.types;
	default_type  application/octet-stream;


	server {
		listen  80;
		listen  443 ssl;
		server_name s1.com;

		ssl_certificate       /var/www/s1.com.pem;
		ssl_certificate_key   /var/www/s1.com.key;

		client_max_body_size 200m;

		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_buffering off

		location / {
			proxy_pass https://192.168.1.11:11;
		}

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

	server {
		listen  80;
		listen  443 ssl;
		server_name *.s1.com;

		ssl_certificate       /var/www/s1.com.pem;
		ssl_certificate_key   /var/www/s1.com.key;

		client_max_body_size 200m;

		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_buffering off

		location / {
			proxy_pass https://192.168.1.11:11;
		}

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



	server {
		listen  80;
		listen  443 ssl;
		server_name s2.com;

		ssl_certificate       /var/www/s2.com.pem;
		ssl_certificate_key   /var/www/s2.com.key;

		client_max_body_size 200m;

		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_buffering off

		location / {
			proxy_pass https://192.168.2.22:22;
		}

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

	server {
		listen  80;
		listen  443 ssl;
		server_name *.s2.com;

		ssl_certificate       /var/www/s2.com.pem;
		ssl_certificate_key   /var/www/s2.com.key;

		client_max_body_size 200m;

		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_buffering off

		location / {
			proxy_pass https://192.168.2.22:22;
		}

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

2. log 配置

vim /etc/logrotate.d/nginx

1
2
3
4
5
6
7
8
9
10
11
12
/var/log/nginx/*.log {
    create 0640 nginx root
    weekly
    rotate 100
    missingok
    notifempty
    delaycompress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}

Ajax使用FormData上传文件

https://www.cnblogs.com/suflowers1700218/p/14230852.html

1 使用form表单初始化FormData对象方式上传文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<form id="uploadForm" enctype="multipart/form-data">
	<input id="file" type="file" name="file"/>
	<button id="upload" type="button">upload</button>
</form>

<script>
$("#upload").click(function () {
	$.ajax({
		url: '/Default/UploadFile',
		type: 'POST',
		cache: false,
		data: new FormData($('#uploadForm')[0]),
		processData: false,
		contentType: false,
		success: function (data) {
			alert(data.result)
		}
	}).fail(function (res) {
		alert("系统错误")
	});
});
</script>

这里要注意几点:

1
2
3
4
5
6
7
8
9
processData设置为false。因为data值是FormData对象,不需要对数据做处理。

<form>标签添加 enctype="multipart/form-data" 属性。

cache设置为false,上传文件不需要缓存。

contentType设置为false,不设置contentType值,因为是由<form>表单构造的FormData对象,且已经声明了属性 enctype="multipart/form-data",所以这里设置为false。

上传后,服务器端代码需要使用从查询参数名为file获取文件输入流对象,因为<input>中声明的是name="file"

2.使用FormData对象添加字段方式上传文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<script>
$("#upload").click(function () {
	var formData = new FormData();
	formData.append('file', $('#file')[0].files[0]);
	$.ajax({
		url: '/Default/UploadFileByFormData',
		type: 'POST',
		cache: false,
		data: formData,
		processData: false,
		contentType: false,
		success: function (data) {
			alert(data.result)
		}
	}).fail(function (res) {
		alert("系统错误")
	});
});
</script>

这里有几处不一样:

1
2
3
4
5
6
7
append()的第二个参数应是文件对象,即$('#file')[0].files[0]。

contentType也要设置为‘false’。

从代码$('#file')[0].files[0]中可以看到一个<input type="file">标签能够上传多个文件,

只需要在<input type="file">里添加multiple或multiple="multiple"属性。

3. Ajax使用FormData上传多个文件

在 input type=“file” 里添加 multiple=“multiple” 属性,选择文件时,按住Ctrl键或Shift键选择多个文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<script type="text/javascript">
$("#upload").click(function () {
	var formData = new FormData();
	for (var i = 0; i < $('#file')[0].files.length; i++) {
		formData.append('files', $('#file')[0].files[i]);
	}
	$.ajax({
		url: '/Default/UploadFilesByFormData',
		type: 'POST',
		cache: false,
		data: formData,
		processData: false,
		contentType: false,
		success: function (data) {
			alert(data.message)
		}
	}).fail(function (res) {
		alert("系统错误")
	});
});
</script>