2023年9月

1.生成 RSA 证书

acme.sh --issue -d www.example.com -w /var/www/ssl/

2.生成 ECC 证书

acme.sh --issue -d www.example.com -w /var/www/ssl/ --keylength ec-256
ECC证书:ECC证书是基于ECC算法的SSL证书,ECC证书中文名称为椭圆加密算法,新一代算法趋势主流,一般采用 256 位加密长度,加密速度快,效率更高,对服务器资源消耗低,而且最重要的是更安全,抗攻击型更强。
RSA证书:RSA证书是基于RSA算法的SSL证书,RSA算法是国际标准算法,应用较早,最为普及,比ECC算法的适用范围更广,兼容性更好,一般采用 2048 位的加密长度,但是对服务端性能消耗高。

3.安装 ECC 证书

acme.sh --installcert -d www.example.com   \
        --key-file   /ssl/www.example.com.key \
        --fullchain-file /ssl/www.example.com.crt \
        --reloadcmd  "systemctl reload nginx" --ecc

4.更新SSL证书

acme.sh --renew -d www.example.com --ecc --force

5.取消SSL证书的自动续期

acme.sh --remove -d www.example.com --ecc

一、系统更新

sudo apt update
sudo apt install apt-transport-https lsb-release ca-certificates curl dirmngr gnupg

二、安装PostgreSQL
1.将官方 PostgreSQL 存储库添加到Debian系统中并导入签名密钥

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

2.安装PostgreSQL

sudo apt update
sudo apt install postgresql

3.配置PostgreSQL

  • 启动和停止 PostgreSQL 服务:

    sudo systemctl start postgresql
    sudo systemctl enable postgresql
  • 创建 PostgreSQL 用户和数据库:
    访问PostgreSQL shell:

    sudo -u postgres psql

    创建用户:

    CREATE USER username WITH PASSWORD 'password';

    创建数据库:

    CREATE DATABASE database_name;
  • 配置 PostgreSQL 安全性
    通过配置认证方式和访问控制,可以保证只有授权的用户才能访问。 您需要修改的配置文件称为“pg_hba.conf”。

    sudo nano /etc/postgresql/<version>/main/pg_hba.conf

    在 pg_hba.conf 文件中,您可以指定不同类型连接的身份验证方法并定义访问控制规则。

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    
    # "local" is for Unix domain socket connections only
    local   all             all                                     peer
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            scram-sha-256
    # IPv6 local connections:
    host    all             all             ::1/128                 scram-sha-256
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    local   replication     all                                     peer
    host    replication     all             127.0.0.1/32            scram-sha-256
    host    replication     all             ::1/128                 scram-sha-256
    
    local   dbname          nginx                                   scram-sha-256
PostgreSQL 15对用户权限这块进行了增强。默认情况,不再设置public schema的CREATE权限。
GRANT CREATE ON SCHEMA public TO username;

一、安装PHP 8.2
1.Debian 12 的默认版本是 PHP 8.2。通过运行以下命令来安装它。

# apt install php-fpm php-cli php-pgsql php-mbstring php-xml php-gd

2.检查安装的 PHP 版本

# php --version
PHP 8.2.10 (cli) (built: Sep  4 2023 08:12:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies

二、配置PHP-FPM
1.设置文件上传大小限制和PHP内存限制

# vi /etc/php/8.2/fpm/php.ini

upload_max_filesize = 50M
...
post_max_size = 50M
...
memory_limit = 256M

2.配置PHP进程用户和组为Nginx的用户和组

# vi /etc/php/8.2/fpm/pool.d/www.conf
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx
group = nginx
...
listen.owner = nginx
listen.group = nginx

3.重新启动PHP-fpm进程。

# systemctl restart php8.2-fpm

三、配置Nginx
1.编辑网站配置文件

# vi /etc/nginx/conf.d/test.web.conf

添加以下内容:

    # Pass PHP Scripts To FastCGI Server
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock; #depends on PHP versions
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

2.验证Nginx配置。

# nginx -t

如果你没有看到任何错误,这意味着你可以正常运行了。
3.重启Nginx服务器

# systemctl start nginx
您是第 67949 位访客