kk Blog —— 通用基础


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

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

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

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
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;

		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;

		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;

		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;

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

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

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>