nginx - nginx 不提供站点地图文件
问题描述
我正在尝试服务器静态站点地图文件,我的 nginx 配置是:-
location /sitemap.xml/ {
autoindex on;
root /var/www/html;
}
所以现在当我尝试做的时候,
www.mysite.com/sitemap.xml
我得到404 not found
错误。
所以当我检查 nginx 错误日志文件时,我看到 nginx 正在尝试搜索站点地图文件
/var/www/html/sitemap.xml/index.html
我不明白为什么它搜索 index.html 文件而不是 sitemap.xml。
解决方案
在root
指令的情况下,完整路径被附加到包含位置部分的根,而在alias
指令的情况下,只有不包括位置部分的路径部分被附加到别名。
因此对于:
location = /sitemap.xml/ {
autoindex on;
root /var/www/html;
}
nginx 将创建最终路径为:
/var/www/html/sitemap.xml/*
假设您在sitemap.xml
目录中没有.../www/html/
目录,这将导致 404 错误。如果是这种情况,您应该使用该alias
指令。在所述位置查找文件之前放置位置路径的位置。
试试这个:
location = /intern/ {
autoindex on;
alias /var/www/html/; # <----- trailing slash is important here
}
这应该导致路径:
/var/www/html/*
推荐阅读
- r - R中光栅(netCDF)计算的速度显着不同
- nginx - 创建到子目录的位置路由
- apache - 413 请求实体太大 apache“tomcat”
- sql - 微软 SQL 服务器 2012; 我有以下语法错误:'关键字'BEGIN'附近的语法不正确。'
- javascript - 如何使用javascript在Acrobat中将一系列两个字段合并为一系列一个字段
- python - Python:如何删除括号内的逗号?
- xamarin - Xamarin,Visual Studio 2017(社区),Main.axml 警告“此项目包含未成功编译的资源”
- c# - 从字符串 C# 应用程序转换日期和/或时间时转换失败
- django - 允许用户在设备上跳过多重身份验证 30 天
- android - Watson unity android 识别不好