git push github失败,提示SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443

今天git push 发现出现错误,很莫名其妙,错误的详情如下:

1
2
fatal: unable to access 'https://github.com/XXXX/XXXX.git/': 
LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443

然后去网上根据这个错误提示搜了一下,发现是因为Git的Http代理的问题,Git支持三种协议:git://、ssh://和http://,本来push的时候应该走ssh隧道的,但是因为设置了http代理,所以就走了http的代理,于是就提交不了了。
OK,找到原因了,那就取消http代理吧:

解决办法

在github项目在本地的根目录下打开git命令行,
执行下面的命令

1
$ git config --global --unset http.proxy

nginx http和https配置

nginx配置详解

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
##
# 全局配置
##

user www-data; ## 配置 worker 进程的用户和组
worker_processes auto; ## 配置 worker 进程启动的数量,建议配置为 CPU 核心数
error_log logs/error.log; ## 全局错误日志
pid /run/nginx.pid; ## 设置记录主进程 ID 的文件
worker_rlimit_nofile 8192; ## 配置一个工作进程能够接受并发连接的最大数

##
# 工作模式及连接数上限
##
events {
# epoll 是多路复用 IO(I/O Multiplexing)中的一种方式,
# 仅用于 Linux 2.6 以上内核,可以大大提高 Nginx 性能
use epoll

# 单个后台 worker process 进程的最大并发链接数
# 并发总数 max_clients = worker_professes * worker_connections
worker_connections 4096; ## Defaule: 1024
# multi_accept on; ## 指明 worker 进程立刻接受新的连接
}

##
# http 模块
##
http {

##
# Basic Settings
##

#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
#对于普通应用,必须设为 on,
#如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off,
#以平衡磁盘与网络 I/O 处理速度,降低系统的 uptime.
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65; ## 连接超时时间
types_hash_max_size 2048; ## 指定散列类型表的最大大小
# server_tokens off;

# server_names_hash_bucket_size 64; # this seems to be required for some vhosts
# server_name_in_redirect off;

include /etc/nginx/mime.types; ## 设定 mine 类型
default_type application/octet-stream;

# 设定请求缓冲
client_header_buffer_size 128k; # 指定客户端请求头缓存大小,当请求头大于 1KB 时会用到该项
large_client_header_buffers 4 128k; # 最大数量和最大客户端请求头的大小

##
# SSL Settings
##

# 启用所有协议,禁用已废弃的不安全的SSL 2 和SSL 3
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
# 让服务器选择要使用的算法套件
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log; ## 访问日志
error_log /var/log/nginx/error.log; ## 错误日志

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";
text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf; # 这个文件夹默认是空的
include /etc/nginx/sites-enabled/*; # 开启的 Server 服务配置

}

##
# mail 模块
##

mail {
# See sample authentication script at:
# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

# auth_http localhost/auth.php;
# pop3_capabilities "TOP" "USER";
# imap_capabilities "IMAP4rev1" "UIDPLUS";

server {
listen localhost:110;
protocol pop3;
proxy on;
}

server {
listen localhost:143;
protocol imap;
proxy on;
}
}

总结来说

1
2
3
4
5
6
main:用于进行nginx全局信息的配置
events:用于nginx工作模式的配置
http:用于进行http协议信息的一些配置
server:用于进行服务器访问信息的配置
location:用于进行访问路由的配置
upstream:用于进行负载均衡的配置

目前使用的一些nginx配置

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
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

#user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
#worker_rlimit_nofile 65535;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
#include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

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

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
# include /etc/nginx/conf.d/*.conf;

# 这段是只http的时候设置的
#***************************************************************************
#server {
#listen 80;
#server_name localhost;

# root /usr/share/nginx/html;

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

#location / {
#proxy_pass http://localhost:8080;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Scheme $scheme;
#proxy_pass_header Server;
#proxy_redirect on;

#}

#}
#***************************************************************************

# 这段是只https的时候设置的
#***************************************************************************
server {
listen 80;
server_name XXX.XXXX.com;
return 301 https://$server_name$request_uri;
}

server {
listen 443;
server_name XXX.XXXX.com;
ssl on;
ssl_certificate cert/XXX.XXXX.pem;
ssl_certificate_key cert/XXX.XXXX.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location /{
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}
}
#****************************************************************************

}

nginx的基本使用

Nginx是一款轻量级的网页服务器、反向代理服务器。相较于Apache、lighttpd具有占有内存少,稳定性高等优势。它最常的用途是提供反向代理服务。关于nginx的安装,网上有很多教程,大家都可以去百度上查找。这篇文章是来记录nginx的基本使用和配置中遇到的错误问题。

学习nginx遇到的一些问题

nginx 找不到安装地址

今天看到了nginx,想到我在服务器里面安装了nginx,只是还没有用到,所以想看下其安装地址,却没有找到,后来谷歌下,发现用nginx -t就可以找到nginx.conf的文件位置,从而知道nginx的安装位置。

1
2
3
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Python基础系列之*args和**kwargs的认识

*args和**kwargs这两个参数咱们经常用到,今天在巩固基础的时候,看到了这两个参数,做了一下对比,所以记录一下。

*args

*args这种写法代表的是 元组,就比如我上面为啥说它们是参数,是因为他们经常在函数的参数中出现。
下面咱们在例子中来说明

Linux find命令的使用

find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访问时间,修改时间等。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。

Supervisor管理进程

Supervisor 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器出问题导致所有应用程序都被杀死,此时可以用 Supervisor 同时启动所有应用程序而不是一个一个地敲命令启动。

安装

Supervisor 可以运行在 Linux、Mac OS X 上。如前所述,Supervisor 是 Python 编写的,所以安装起来也很方便,可以直接用 pip 安装:

1
$ sudo pip install supervisor

因为supervisor,只能安装在python2.X上面,目前开发用的是3.5.0,所以这里用到了pyenv。pyenv来管理用python2.X还是python3.X。学习pyenv请点链接:pyenv

配置

Supervisor 相当强大,提供了很丰富的功能,不过我们可能只需要用到其中一小部分。安装完成之后,可以编写配置文件,来满足自己的需求。为了方便,我们把配置分成两部分 Supervisor(Supervisor 是一个 C/S 模型的程序,这是 server 端,对应的有 client 端:supervisorctl)和应用程序(即我们要管理的程序)

首先来看 Supervisor 的配置文件。安装完 Supervisor 之后,可以运行 echo_supervisord_conf 命令输出默认的配置项,也可以重定向到一个配置文件里:

1
echo_supervisord_conf > /etc/supervisord.conf

去除里面大部分注释和“不相关”的部分,我们可以先看这些配置:

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
[unix_http_server]
file=/tmp/supervisor.sock ; UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ; socket 文件的 mode,默认是 0700
;chown=nobody:nogroup ; socket 文件的 owner,格式: uid:gid
;[inet_http_server] ; HTTP 服务器,提供 web 管理界面
;port=127.0.0.1:9001 ; Web 管理后台运行的 IP 和端口,如果开放到公网,需要注意安全性
;username=user ; 登录管理后台的用户名
;password=123 ; 登录管理后台的密码
[supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10 ; 日志文件保留备份数量默认 10
loglevel=info ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024 ; 可以打开的文件描述符的最小值,默认 1024
minprocs=200 ; 可以打开的进程数的最小值,默认 200
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; 通过 UNIX socket 连接 supervisord,路径与 unix_http_server 部分的 file 一致
;serverurl=http://127.0.0.1:9001 ; 通过 HTTP 的方式连接 supervisord
; 包含其他的配置文件
[include]
files = relative/directory/*.ini ; 可以是 *.conf 或 *.ini

我们把上面这部分配置保存到 /etc/supervisord.conf(或其他任意有权限访问的文件)然后启动 supervisord(通过 -c 选项指定配置文件路径,如果不指定会按照这个顺序查找配置文件:$CWD/supervisord.conf, $CWD/etc/supervisord.conf, /etc/supervisord.conf)

1
supervisord -c /etc/supervisord.conf

查看 supervisord 是否在运行:

1
ps aux | grep supervisord

program 配置

上面我们已经把 supervisrod 运行起来了,现在可以添加我们要管理的进程的配置文件。可以把所有配置项都写到 supervisord.conf 文件里,但并不推荐这样做,而是通过 include 的方式把不同的程序(组)写到不同的配置文件里。
为了举例,我们新建一个目录 /etc/supervisor/ 用于存放这些配置文件,相应的,把 /etc/supervisord.conf 里 include 部分的的配置修改一下:

1
2
[include]
files = /etc/supervisor/*.conf

假设有个用 Python 和 Flask 框架编写的用户中心系统,取名 usercenter,用 gunicorn 做 web 服务器。项目代码位于 /home/leon/projects/usercenter,gunicorn 配置文件为 gunicorn.py,WSGI callable 是 wsgi.py 里的 app 属性。所以直接在命令行启动的,方式可能是这样的:

1
2
cd /home/leon/projects/usercenter
gunicorn -c gunicorn.py wsgi:app

现在编写一份配置文件来管理这个进程(需要注意:用 supervisord 管理时,gunicorn 的 daemon 选项需要设置为 False):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[program:usercenter]
directory = /home/leon/projects/usercenter ; 程序的启动目录
command = gunicorn -c gunicorn.py wsgi:app ; 启动命令,可以看出与手动在命令行启动的命令是一样的
autostart = true ; 在 supervisord 启动的时候也自动启动
startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true ; 程序异常退出后自动重启
startretries = 3 ; 启动失败自动重试次数,默认是 3
user = leon ; 用哪个用户启动
redirect_stderr = true ; 把 stderr 重定向到 stdout,默认 false
stdout_logfile_maxbytes = 20MB ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups = 20 ; stdout 日志文件备份数
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile = /data/logs/usercenter_stdout.log
; 可以通过 environment 来添加需要的环境变量,一种常见的用法是修改 PYTHONPATH
; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere

一份配置文件至少需要一个 [program:x] 部分的配置,来告诉 supervisord 需要管理那个进程。[program:x] 语法中的 x 表示 program name,会在客户端(supervisorctl 或 web 界面)显示,在 supervisorctl 中通过这个值来对程序进行 start、restart、stop 等操作