网站搭建完成后,SEO(搜索引擎优化)配置直接决定了网站能否从Google等搜索引擎获取自然流量。本文介绍VPS建站后必须完成的SEO基础配置,涵盖技术SEO的核心要点。
robots.txt告诉搜索引擎哪些页面可以抓取,哪些应该忽略。放置在网站根目录。
# /var/www/yoursite/robots.txt
User-agent: *
Allow: /
# 禁止抓取后台和敏感目录
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
Disallow: /cart/
Disallow: /checkout/
Disallow: /my-account/
# Sitemap位置
Sitemap: https://yourdomain.com/sitemap.xml
配置完成后,可在Google Search Console中测试robots.txt是否正确解析。
Sitemap帮助搜索引擎发现和索引网站的所有页面。
安装Yoast SEO或Rank Math插件,自动生成Sitemap:
https://yourdomain.com/sitemap_index.xmlhttps://yourdomain.com/sitemap_index.xml手动创建或使用工具生成sitemap.xml:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://yourdomain.com/</loc>
<lastmod>2026-03-01</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://yourdomain.com/products/</loc>
<lastmod>2026-03-15</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
在Google Search Console中,进入「Sitemaps」页面,提交Sitemap URL。同时在Bing Webmaster Tools中也提交一份。
页面加载速度是Google排名的重要因素(Core Web Vitals)。
# /etc/nginx/nginx.conf 优化
worker_processes auto;
worker_rlimit_nofile 65535;
events {
worker_connections 4096;
multi_accept on;
}
http {
# Gzip压缩
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript
text/xml application/xml application/xml+rss text/javascript
image/svg+xml;
# 静态文件缓存
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# 开启sendfile
sendfile on;
tcp_nopush on;
tcp_nodelay on;
}
# /etc/php/8.2/fpm/conf.d/10-opcache.ini
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.interned_strings_buffer=16
# MySQL查询缓存和连接优化
[mysqld]
innodb_buffer_pool_size = 256M
query_cache_type = 1
query_cache_size = 64M
max_connections = 150
结构化数据(Schema.org)帮助搜索引擎理解页面内容,可获得Rich Snippet展示。
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "文章标题",
"description": "文章描述",
"author": {"@type": "Person", "name": "作者"},
"datePublished": "2026-03-01",
"publisher": {
"@type": "Organization",
"name": "网站名称"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Product",
"name": "产品名称",
"description": "产品描述",
"offers": {
"@type": "Offer",
"price": "29.99",
"priceCurrency": "USD",
"availability": "https://schema.org/InStock"
}
}
</script>
使用Google的Rich Results Test工具验证结构化数据是否正确。
HTTPS是SEO的基本要求。在Nginx中配置安全响应头:
# 安全头配置
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
CN2 GIA线路低延迟有助于Google爬虫快速抓取,提升抓取效率。
价格:$49.99/季起,使用优惠码 NODESEEK2026 再省6.77%。
Tip: 配合Cloudflare CDN使用效果更佳,更多教程请查看新手教程。