【问题标题】:How to configure NGINX to render the sitemap.xml before Angular 5 Application loads如何配置 NGINX 在加载 Angular 5 应用程序之前呈现 sitemap.xml
【发布时间】:2018-08-12 11:17:13
【问题描述】:

我有一个在 NodeJS 服务器上运行的 Angular 5 应用程序,我想在 website.com/sitemap/sitemap-cats.xmlexample.com/sitemap/sitemap-dogs.xml 呈现我的站点地图

我的站点地图位于/home/root/sitemap 文件夹。

我尝试如下配置/nginx/sites-available/default 的位置块,因此它会在加载 Angular 应用程序之前呈现站点地图。

    # Sitemap Locations
    location /sitemap/sitemap-cats.xml {
            alias /home/root/sitemap/sitemap-cats.xml;
    }

    location /sitemap/sitemap-dogs.xml {
            alias /home/root/sitemap/sitemap-dogs.xml;
    }

问题是上面的配置不起作用,因此 Angular 应用程序显示 404 错误。

甚至可以在 Angular 应用加载之前渲染这些 .xml 文件吗?

【问题讨论】:

    标签: node.js angular nginx nginx-location


    【解决方案1】:

    试试这个

    # Sitemap Locations
    location /sitemap/ {
            alias /home/root/sitemap/;
    }
    

    【讨论】:

    • 我也试过了,然后用 'sudo systemctl restart nginx' 重启了 nginx,但是站点地图仍然没有显示出来。
    • 然后尝试调试nginx。您是仅将它用于静态文件,还是也用作 nodejs 的代理?
    • 我也用它作为nodejs的反向代理。
    • 反向代理是使用默认网站设置的,而不是虚拟主机?
    • 在这种情况下你需要看看 nginx 在做什么。在错误日志配置的末尾添加debug,如下所示:error_log /path/to/log debug;,然后向站点地图文件发出请求,并在日志文件中查看发生了什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2017-04-23
    • 1970-01-01
    相关资源
    最近更新 更多