VPS建站SEO优化基础配置


网站搭建完成后,SEO(搜索引擎优化)配置直接决定了网站能否从Google等搜索引擎获取自然流量。本文介绍VPS建站后必须完成的SEO基础配置,涵盖技术SEO的核心要点。

一、robots.txt配置

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是否正确解析。

二、XML Sitemap生成

Sitemap帮助搜索引擎发现和索引网站的所有页面。

2.1 WordPress站点

安装Yoast SEO或Rank Math插件,自动生成Sitemap:

2.2 静态网站或自定义程序

手动创建或使用工具生成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>

2.3 提交Sitemap

在Google Search Console中,进入「Sitemaps」页面,提交Sitemap URL。同时在Bing Webmaster Tools中也提交一份。

三、网站速度优化

页面加载速度是Google排名的重要因素(Core Web Vitals)。

3.1 Nginx性能配置

# /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;
}

3.2 PHP OPcache优化

# /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

3.3 数据库优化

# MySQL查询缓存和连接优化
[mysqld]
innodb_buffer_pool_size = 256M
query_cache_type = 1
query_cache_size = 64M
max_connections = 150

3.4 图片优化

四、结构化数据配置

结构化数据(Schema.org)帮助搜索引擎理解页面内容,可获得Rich Snippet展示。

4.1 文章页面

<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>

4.2 产品页面(电商站)

<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和安全头配置

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;

六、其他SEO要点

推荐VPS方案

CN2 GIA-E 方案(建站SEO首选)

CN2 GIA线路低延迟有助于Google爬虫快速抓取,提升抓取效率。

价格:$49.99/季起,使用优惠码 NODESEEK2026 再省6.77%。

查看CN2 GIA-E方案

Tip: 配合Cloudflare CDN使用效果更佳,更多教程请查看新手教程
关于本站

搬瓦工VPS中文网(bwgvps.com)是非官方中文信息站,整理搬瓦工 BandwagonHost 的优惠信息、使用教程和方案对比,方便中文用户选购和使用。

新手必读
搬瓦工优惠码

当前最大折扣优惠码:

NODESEEK2026(优惠 6.77%)

在购买方案时填入优惠码即可自动抵扣。详见 优惠码使用教程