這讓我瘋狂......我在路由器定義中添加了一個路由來提供純文本robots.txt文件。我不認爲我在/robots.txt路由之前有一個catchall,因爲到/ mobile和/ map的其他路由按預期工作。在我的本地機器上,/robots.txt工作正常。只有在部署到服務器時,這條路線才能工作。robots.txt沒有通過node.js顯示路由發送純文本
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
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
編輯:
您確定在添加該路由後重新啓動了您的節點服務器嗎?嘗試從Express直接(在您的服務器上)請求'/ robots.txt',而不是通過nginx。 – robertklep
我想這是靜態文件攔截問題。你可以在'server'中顯示nginx配置,特別是'location'部分嗎? – Nevertheless
這不是nginx設置。我可以從IP地址打開網站,但robots.txt未打開。 http://139.59.161.58:3000/robots.txt –