1.
小分段:选择原因 — 台湾CN2线路对大陆访问延迟低、稳定;适合面向中国大陆用户的站点。
小分段:购买提示 — 选择带有KVM/独立IP、1G以上内存(建议2G起)、固定带宽或按流量计费都可。确认是否提供IPv4、是否支持换区、是否允许自助重装系统。
2.
小分段:SSH登录 — 拿到IP后,用终端 ssh root@你的IP 登录(Windows可用PuTTY或Windows Terminal)。
小分段:设置SSH密钥(推荐) — 本地生成:ssh-keygen -t rsa -b 4096;上传到服务器:mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo "你的公钥" >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys。
小分段:限制root登录与更换端口 — 编辑 /etc/ssh/sshd_config,将PermitRootLogin no,Port 2222(示例),然后 systemctl restart sshd。
3.
小分段:更新系统 — Debian/Ubuntu:apt update && apt upgrade -y;CentOS:yum update -y。
小分段:时区与时间同步 — ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime;安装ntp或timesyncd并启用。
小分段:添加非root用户并赋sudo — adduser username && usermod -aG sudo username(Debian系);切换并测试。
小分段:基础防火墙 — UFW示例:apt install ufw -y;ufw allow 2222/tcp;ufw allow 80/tcp;ufw allow 443/tcp;ufw enable。
4.
小分段:安装命令(Debian/Ubuntu示例) — apt install nginx mariadb-server php8.1-fpm php8.1-mysql -y。
小分段:启动并开机自启 — systemctl enable --now nginx php8.1-fpm mariadb。
小分段:MariaDB安全设置 — mysql_secure_installation,设置root密码、移除匿名用户、禁止远程root登录、删除测试库。
5.
小分段:DNS解析 — 在域名服务商添加A记录,主机记录 @(或www)指向VPS公网IP,TTL可设低值便于调试。
小分段:Nginx虚拟主机示例 — 在 /etc/nginx/sites-available/example.com.conf 写入:
server { listen 80; server_name example.com www.example.com; root /var/www/example.com/html; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } access_log /var/log/nginx/example.com.access.log; error_log /var/log/nginx/example.com.error.log; }
小分段:启用站点并测试 — mkdir -p /var/www/example.com/html; chown -R www-data:www-data /var/www/example.com; ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/; nginx -t && systemctl reload nginx。
6.
小分段:安装Certbot并获取证书(Debian示例) — apt install certbot python3-certbot-nginx -y;certbot --nginx -d example.com -d www.example.com。
小分段:自动续签 — certbot renew --dry-run,系统会自动在cron或systemd定时续签(检查 /etc/cron.d 或 systemctl list-timers)。
小分段:启用HTTP/2与安全头 — 在ssl配置中使用 listen 443 ssl http2; 添加 add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;。
7.
答:计算方法 — 先估算单个PHP进程平均占用内存(ps aux | grep php-fpm 或通过top观察),用可用RAM减去系统与MySQL占用,再用剩余内存(MB)除以单进程内存。例如:VPS 2GB,系统与DB占用600MB,剩余约1400MB;单个进程约40MB,则 max_children ≈ 1400 / 40 = 35。将 pm = dynamic, pm.max_children = 35, pm.start_servers、min/max 按需调整。
8.
答:开启步骤 — 编辑 /etc/sysctl.conf 添加:net.core.default_qdisc = fq 和 net.ipv4.tcp_congestion_control = bbr;保存后执行 sysctl -p。检查是否生效:sysctl net.ipv4.tcp_congestion_control(应显示 bbr),或 lsmod | grep bbr。若内核不支持,需升级内核或选择提供支持BBR的镜像。
9.
答:实践建议 — 1)启用HTTP/2与gzip/brotli压缩减少数据量;2)在Nginx中启用 sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; 3)使用静态资源CDN或将静态文件放到子域并设置长缓存;4)调整MTU和路径MTU探测(tracepath/mturoute)排查中间丢包,必要时联系VPS商优化路由;5)开启缓存(fastcgi_cache 或 Redis、Memcached)减少后端压力。