for k in list(result.keys()):
if not result.get(k):
del result[k] Python 按键(key)或值(value)对字典进行排序
按照键值(key)排序
key_value[2] = 56
key_value[1] = 2
key_value[5] = 12
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
print ("按键(key)排序:")
sorted(key_value) 返回重新排序的列表
字典按键排序
for i in sorted (key_value) :
print ((i, key_value[i]), end =" ")
按照值(value)排序
key_value ={}
key_value[1] = 2
key_value[5] = 12
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
print ("按值(value)排序:")
print(sorted(key_value.items(), key = lambda kv:(kv[1], kv[0])))
如果是降序,则sorted(lis, key = lambda i: i['age'],reverse=True)
AlpineLinux 修改时区及同步日期
apk --update add --no-cache tzdata
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
rc-service chronyd restart AlpineLinux下安装Nginx、PHP-fpm、Mariadb
安装Nginx
安装
apk add nginx创建用户及网站路径
adduser -g 'Nginx www user' -h /home/www/ webmaster配置Nginx
vim /etc/nginx/httpd.d/defaut
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/www;
# Everything is a 404
location / {
return 404;
}
# You may need this to prevent return 404 recursion.
location = /404.html {
internal;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}}
启动Nginx,并加入系统
rc-service nginx start
rc-update add nginx default
安装Php
安装
apk add php7 php7-fpm php7-opcache安装库
apk add php7-mysqli php7-mbstring php7-json php7-zlib php7-gd php7-intl php7-session
启动PHP,并加入系统
rc-service php-fpm7 start
rc-update add php-fpm7 default
安装Mariadb
安装
apk add mariadb mariadb-common mariadb-client初始化
/etc/init.d/mariadb setup
/etc/init.d/mariadb start
mysql_secure_installation启动Mariadb,并加入系统
rc-service mariadb restart
rc-update add mariadb defaultAlpineLinux下,默认的sshd_config中AllowTcpForwarding设置为no,这样mysql等无法通过SSH tunnel访问,需要设为yes。
Ubuntu下安装 Let's Encrypt 获取免费证书
Ubuntu下安装 Let's Encrypt 获取免费证书
安装Cerbot
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt upgrade申请证书
certbot certonly根据提示输入域名及服务器网站的根目录,即可申请成功。证书所在目录为 /etc/letsencrypt/live/下
设置nginx
修改nginx网站配置文件,在原server设置location / 中添加:
return 301 https://domain.com$request_uri;新建一个server,在基础设置选项中:
server {
listen 443 ssl;
root /var/www/html/blog;
index index.php index.html index.htm;
server_name blog.zijide.net;
ssl on;
ssl_certificate /etc/letsencrypt/live/blog.zijide.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.zijide.net/privkey.pem;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}重启nginx服务器
证书到期续申请
停止服务器后
certbot renew