我有一个名为http://www.domain.com/sitemap1.php的网站地图。 它从这个代码开始:
<?php echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ';
从Apache转移到Nginx后,Google网站pipe理员工具开始拒绝我的站点地图告诉我他们看起来像HTML页面。
看着输出,我看到一些奇怪的东西。
使用Nginx:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><head/><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
使用Apache:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
由于某种原因,我不明白Nginx的投入
<head/>
在urlset之前。
有人知道这个的原因吗? 恐怕这是导致问题的原因。 但即使search,我没有find答案。
我不知道回答我自己的问题是否正确。 但过了几天,我终于find了解决办法。
我想感谢阿列克谢十提到单词“模块”。 这似乎是pagespeed模块是问题。 禁用nginxconfiguration文件中的pagespeed解决了这个问题。 我已经阅读pagespeed只改变html,所以可能pagespeed认为这个XML输出是HTML。 我再次启用pagespeed并添加:
header('Content-Type: text/xml');
在.php文件中。 现在一切正常。 奇怪的是,我也使用Apache的页面速度模块,从来没有这个问题。 与Apache相比,Nginx的pagespeed行为可能有所不同。