【问题标题】:404 Not found for sitemap.xml on nuxt.js404 在 nuxt.js 上找不到 sitemap.xml
【发布时间】:2020-04-05 12:39:36
【问题描述】:

我正在使用 nuxt.js sitemap-module 生成 sitemap.xml 它与本地的npm run build && npm run start 完美配合。

但是,当它使用 Nginx 在云上时,它就不起作用了。 https://vtapau.com/sitemap.xml

这是我的 Nginx 配置

server {
        listen 80;
        server_name vtapau.com www.vtapau.com;

        location / {
                proxy_pass http://localhost:8081/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_redirect off;
        }
}

【问题讨论】:

    标签: javascript nginx nuxt.js sitemap


    【解决方案1】:

    首先,我真的不知道这是否是对您的有效答案,正如您提到的您已将手动创建的站点地图放入静态文件夹中。

    我认为您错误地配置了站点地图,为了使 sitemap.xml 正常工作,您在站点地图对象中设置了路线:

    // nuxt.config.js
    
    {
      sitemap: {
        hostname: 'https://example.com',
        gzip: true,
        exclude: [
          '/secret',
          '/admin/**'
        ],
        routes: [
          '/page/1',
          '/page/2',
          {
            url: '/page/3',
            changefreq: 'daily',
            priority: 1,
            lastmod: '2017-06-30T13:30:00.000Z'
          }
        ]
      }
    }
    

    当我被要求选择语言时,我怀疑您的站点地图已拆分为不同的语言。我设法得到英文版站点地图here

    如果您的站点地图配置如下:

    // nuxt.config.js
    
    {
       sitemap: {
         hostname: 'https://example.com',
         lastmod: '2017-06-30',
         sitemaps: [
           {
              path: '/sitemap-foo.xml',
              routes: ['foo/1', 'foo/2'],
              gzip: true
           }, {
              path: '/folder/sitemap-bar.xml',
              routes: ['bar/1', 'bar/2'],
              exclude: ['/**']
           }
         ]
       }
    }
    

    您应该可以通过https://vtapau.com/sitemapindex.xml 获取您的站点地图。我希望这不是您创建的静态 xml,否则我已经无能为力了。该文档在sitemap-module 中明确提及,当配置错误时总是返回 github 文档或通过那里的 github 问题找到答案。

    • 也很高兴看到马来西亚新成立的食品配送公司。

    【讨论】:

      【解决方案2】:

      我遇到了完全相同的问题。然后我发现在生产服务器中,Nuxt 服务器是使用nuxt start 启动的,而不是我在本地使用的nuxt-ts start。这是我的问题。希望对您有所帮助。

      【讨论】:

      • 您好,我使用 pm2 启动,它也是 nuxt-ts start。无论如何感谢您的帮助!
      【解决方案3】:

      运行npm run build 后重新启动您的 PM2 服务器。否则,/sitemap.xml 将不会出现。

      我就是这样。

      我的站点地图模块配置:

      sitemap: {
         hostname: 'https://example.com',
         gzip: true,
         exclude: ['/exampleurl']
      }
      

      【讨论】:

      • 我已经做到了。不确定是否是因为我在 AWS CodeDeploy 中使用 bitbucket 管道
      【解决方案4】:

      我使用 Typescript 配置文件 nuxt.config.ts 修复了 AWS lambda 部署中的相同错误。

      要修复它,请替换 const config: NuxtConfig = { }module.exports = { }

      【讨论】:

        猜你喜欢
        • 2018-05-03
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 2015-03-19
        • 2020-01-30
        • 2021-09-26
        • 2014-06-18
        • 1970-01-01
        相关资源
        最近更新 更多