logo小熊博客
首页 fk标记语言示例 登录
目录
新服务器初始化及博客迁移

✅ Ubuntu 22.04 初始化操作步骤

🔧 1. 更新系统 & 安装常用工具

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget git unzip htop net-tools ufw build-essential sudo vim

👤 2. 创建普通用户(推荐关闭 root 登录)

sudo adduser 123456           # 替换为你想用的用户名
sudo usermod -aG sudo 123456  # 加入 sudo 权限

🔐 3. 设置 SSH 公钥登录(更安全)

在本地生成密钥(如尚未生成):

ssh-keygen -t rsa -b 4096

上传公钥到服务器(替换成你的 IP 和用户名):

ssh-copy-id 123456@你的服务器IP

或者手动拷贝公钥粘贴到:

sudo mkdir -p /home/123456/.ssh
sudo nano /home/123456/.ssh/authorized_keys
sudo chown -R 123456:123456/home/123456/.ssh
chmod 700 /home/123456/.ssh
chmod 600 /home/123456/.ssh/authorized_keys

🚫 4. 禁止 root 登录(更安全,选做)

编辑 SSH 配置:

sudo nano /etc/ssh/sshd_config

修改或添加:

PermitRootLogin no
PasswordAuthentication no

然后重启 SSH 服务:

sudo systemctl restart ssh

---

🔥 5. 启用防火墙并开放必要端口

sudo ufw allow OpenSSH
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable

🌍 6. 设置时区为中国大陆(或你所需地区)

sudo timedatectl set-timezone Asia/Shanghai

💾 8. 内存较小时配置 Swap(例如内存 < 2G)

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

✅ 完成后检查项

htop      # 查看资源使用情况
sudo ufw status
whoami    # 当前用户
hostnamectl

博客迁移

步骤一:安装Nginx

sudo apt update
sudo apt -y install nginx
sudo nginx -v

步骤二:安装并配置PHP

sudo apt -y install php-fpm
sudo php -v
sudo apt install php8.1-curl    //安装cURL 扩展
sudo apt install php8.1-gd      //安装GD图形扩展

sudo nano /etc/php/8.1/fpm/php.ini
upload_max_filesize = 50M       //单个上传文件最大限制
post_max_size = 50M             //POST 请求体最大限制

sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx

步骤三:配置nginx文件

sudo vim /etc/nginx/sites-enabled/default
配置php服务
location ~ .php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;  # 根据 PHP 版本调整
}
配置伪静态
location / {
   if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
   }
}

步骤四:申请https证书

准备工作
  1. 你的服务器是 Ubuntu 系统(推荐 20.04+)
  2. 域名 xxcxx.xin 已正确解析到该服务器 IP
  3. 已安装并配置 Nginx(网站已能通过 http 访问)
安装 Certbot 和 Nginx 插件
sudo apt install certbot python3-certbot-nginx -y
使用 Certbot 为 Nginx 自动申请证书
sudo certbot --nginx -d xxcxx.xin -d www.xxcxx.xin
下一篇:vim、nano编辑器快捷键
请我喝奶茶!
赞赏码
手机扫码访问
手机访问