首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >robots.txt未通过node.js路由显示发送纯文本

robots.txt未通过node.js路由显示发送纯文本
EN

Stack Overflow用户
提问于 2016-09-20 13:34:47
回答 2查看 1.4K关注 0票数 1

把我逼疯了..。我在路由器定义中添加了一个路由,以提供一个纯文本robots.txt文件。我认为,在/robots.txt路由之前,我并没有像预期的那样运行到/mobile和/map的其他路由。在我的本地机器上,/robots.txt工作正常。只有当部署到服务器时,此路由才不能工作。

代码语言:javascript
复制
router.get('/', function (req, res) {
    res.render('index');
});

router.get('/mobile', function (req, res) {
    res.render('mobile');
});

router.get('/map', function (req, res) {
    res.render('map');
});

router.get('/robots.txt', function (req, res) {
    res.type('text/plain');
    res.send('User-agent: *');
});

这在我的本地机器上工作得很好,但部署到http://geolytix.co.uk/robots.txt时就不行了。

代码语言:javascript
复制
Error: Not Found
   at /usr/share/geolytix/app.js:28:13
   at Layer.handle [as handle_request] (/usr/share/geolytix/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/usr/share/geolytix/node_modules/express/lib/router/index.js:312:13)
   at /usr/share/geolytix/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/usr/share/geolytix/node_modules/express/lib/router/index.js:330:12)
   at next (/usr/share/geolytix/node_modules/express/lib/router/index.js:271:10)
   at /usr/share/geolytix/node_modules/express/lib/router/index.js:618:15
   at next (/usr/share/geolytix/node_modules/express/lib/router/index.js:256:14)
   at Function.handle (/usr/share/geolytix/node_modules/express/lib/router/index.js:176:3)
   at router (/usr/share/geolytix/node_modules/express/lib/router/index.js:46:12)

我最初的猜测是,这与从nginx到我的节点服务器的代理有关,但我可以直接访问IP地址来访问站点。然而,robots.txt路线失败了。

http://139.59.161.58:3000/robots.txt

编辑:

这是我的app.js第28行

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-21 13:49:36

该应用程序在PM2中重新启动15次失败后崩溃,缓存的版本仍在运行中。robots.txt路由不在缓存中。我很抱歉浪费了你的时间。至少我现在对如何使用PM2有了更好的理解。

D

票数 3
EN

Stack Overflow用户

发布于 2016-09-20 13:52:39

这是因为nginx配置被设置为拦截静态文件请求。

像这样的部分:

代码语言:javascript
复制
http {
    ...
    server {
        ...
        location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
            root /usr/local/.../public;
            access_log off;
            expires max;
        }
        ...
    }
}

正在处理robots.txt,甚至在它到达Express.js路由中间件之前。

您应该从nginx配置中排除文件,以允许路由处理它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39595604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档