准备工作:
- 一台服务器(本教程使用的环境:Ubuntu 24.04/x86_64)
- 安装SSH连接工具Finalshell:【点击进入】
1、开源项目:【点击进入】
2、申请SSL证书(注意:脚本自带关闭防火墙功能,适合Vultr使用,其他平台可在控制台中添加规则放行所有端口)
sudo apt install git -y && git clone https://github.com/slobys/SSL-Renewal.git /tmp/acme && mv /tmp/acme/* /root && bash acme_2.0.sh
3、安装 Nginx
apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
- 将官方 Nginx 源设置为比系统内置源具有更高的优先级
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
apt update
apt install nginx
systemctl start nginx
systemctl enable nginx
4、安装 PHP
- 使用来自 deb.sury.org 的 PPA 源安装 PHP
add-apt-repository ppa:ondrej/php
apt update
apt install -y php8.4-{bcmath,bz2,cli,common,curl,fpm,gd,igbinary,mbstring,mysql,opcache,readline,redis,xml,yaml,zip}
systemctl start php8.4-fpm
systemctl enable php8.4-fpm
5、安装 MariaDB
apt install -y apt-transport-https curl && mkdir -p /etc/apt/keyrings && curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
- 进入/etc/apt/sources.list.d,创建mariadb.sources文件并写入以下配置
X-Repolib-Name: MariaDB
Types: deb
URIs: https://deb.mariadb.org/11.4/ubuntu
Suites: noble
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
apt update
apt install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb
mariadb-secure-installation
6、安装 Redis
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
apt update
apt install -y redis
- 启动 redis-server 服务并将其设置为开机启动
systemctl start redis-server
systemctl enable redis-server
7、部署NeXT Panel
- 打开
/etc/nginx/nginx.conf文件,把user nginx;改成user www-data;
- 进入/etc/nginx/conf.d目录,然后创建website-domain-you-set.conf文件
- 把以下代码添加进去(红色部分根据自己实际情况填写)
# 监听 80 端口,并重定向到 HTTPS
server {
listen 80;
listen [::]:80;
server_name 你的域名;
# 301 永久重定向到 HTTPS
return 301 https://$host$request_uri;
}
# HTTPS 服务器配置
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 你的域名;
root /var/www/nextpanel/public; # 你的网站路径
index index.php;
ssl_certificate /etc/letsencrypt/live/aa.naiyou168.xyz/fullchain.pem; # 证书路径
ssl_certificate_key /etc/letsencrypt/live/aa.naiyou168.xyz/privkey.pem; # 私钥路径
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# 主要的 location 配置
location / {
try_files $uri /index.php$is_args$args;
}
# 处理 PHP 请求
location ~ \.php$ {
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
}
}
systemctl restart nginx
mkdir -p /var/www
cd /var/www
- 下载 NeXT-Panel(红色部分根据实际情况替换成最新版本)
wget https://github.com/SSPanel-NeXT/NeXT-Panel/releases/download/24.5.1/NeXT-Panel-24.5.1.zip
unzip NeXT-Panel-24.5.1.zip -d /var/www/nextpanel ; rm -f NeXT-Panel-24.5.1.zip
chmod -R 755 *
chown -R www-data:www-data *
mariadb -u root -p
- 输入刚创建的密码,使用编码
utf8mb4_unicode_ci和创建一个数据库,以 sspanel 为例
CREATE DATABASE sspanel CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
- 创建一个本地数据库用户,并将用户的权限限制到新创建的数据库,使用 sspanel 作为用户名,使用 sspanel-password 作为用户密码(输入exit即可退出)
CREATE USER 'sspanel'@'localhost';
GRANT ALL PRIVILEGES ON sspanel.* TO 'sspanel'@'localhost' IDENTIFIED BY 'sspanel-password';
FLUSH PRIVILEGES;
cd /var/www/nextpanel
cp config/.config.example.php config/.config.php
cp config/appprofile.example.php config/appprofile.php
- 进入/var/www/nextpanel/config,打开.config.php,然后输入前面设置好的数据库账号、密码
php xcat Migration new
php xcat Tool importSetting
php xcat Tool createAdmin
sudo -u www-data /usr/bin/php xcat ClientDownload
- 设置定时任务,输入crontab -e,然后选择1,在最后面添加一下代码(输入完成后按Ctrl+X退出,然后输入y,回车)
*/5 * * * * /usr/bin/php /path/to/your/site/xcat Cron
8、提高系统安全性和性能
sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' /etc/php/8.4/fpm/php.ini
sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' /etc/php/8.4/cli/php.ini
systemctl restart php8.4-fpm
- 进入/etc/php/8.4/fpm/conf.d,打开10-opcache.ini,然后添加一下代码
zend_extension=opcache.so
opcache.file_cache=/tmp
opcache.interned_strings_buffer=64
opcache.jit=on
opcache.jit_buffer_size=256M
opcache.max_accelerated_files=65535
opcache.memory_consumption=512
opcache.revalidate_freq=60
opcache.validate_permission=on
opcache.validate_root=on
systemctl restart php8.4-fpm
0 评论