IT记录

日常学习、工作的点滴记录


  • 首页

  • categories

  • archive

  • tags

  • 搜索

python删除字典中value为空的键值

发表于 2021-11-09   |   分类于 Python   |   暂无评论
for k in list(result.keys()):
    if not result.get(k):
        del result[k]

Python 按键(key)或值(value)对字典进行排序

发表于 2021-11-09   |   分类于 Python   |   暂无评论

按照键值(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 修改时区及同步日期

发表于 2021-11-04   |   分类于 系统应用   |   暂无评论
apk --update add --no-cache tzdata
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
rc-service chronyd restart

AlpineLinux下安装Nginx、PHP-fpm、Mariadb

发表于 2021-11-03   |   分类于 系统应用   |   暂无评论

安装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 default

AlpineLinux下,默认的sshd_config中AllowTcpForwarding设置为no,这样mysql等无法通过SSH tunnel访问,需要设为yes。

Ubuntu下安装 Let's Encrypt 获取免费证书

发表于 2021-11-02   |   分类于 系统应用   |   暂无评论

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
1...89101112131415161718...23

一个高端大气上档次的网站

115 文章
5 分类
51 标签
GitHub 知乎 V2EX SF
© 2026 IT记录
Typecho
主题 - NexT.Pisces