Ubuntu环境下SEO优化实操指南
一 基础架构与服务器配置
sudo systemctl reload nginx。sudo apt install certbot python3-certbot-nginx && sudo certbot --nginx -d yourdomain.com;Apache 执行 sudo apt install certbot python3-certbot-apache && sudo certbot --apache -d yourdomain.com。sudo netplan apply 使配置生效。sudo ufw enable),SSH 安全加固(如禁用 root 登录、使用密钥登录、按需修改端口),并保持系统与软件包 及时更新。二 性能与速度优化
三 内容与站内技术SEO
四 监测、验证与维护
五 Nginx 与 Apache2 关键配置示例
# /etc/nginx/nginx.conf 或站点 server 块内
gzip on;
gzip_vary on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
location ~* \.(jpg|jpeg|png|webp|gif|ico|css|js)$ {
expires 1M;
add_header Cache-Control "public, immutable";
}
# 启用模块
sudo a2enmod deflate expires rewrite
sudo systemctl restart apache2
# .htaccess 或虚拟主机配置
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 week"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
# 前端控制器或 SEO 友好 URL 重写
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [QSA,L]
以上示例分别展示了在 Nginx 中启用 Gzip 与资源缓存,以及在 Apache2 中启用 mod_deflate/mod_expires/mod_rewrite 的基础做法,可直接按需集成到现有站点配置中。