簡體   English   中英

在生產服務器上進行快速路由

[英]express routing on production server

我正在嘗試從本地環境到生產環境部署節點應用程序。

在我的本地環境中,我的代碼看起來像下面的代碼,並且一切正常。 導航至localhost:3000 ,單擊登錄,然后進入login路徑。

本地app.js文件

var express = require('express');
var bodyParser = require("body-parser");

var app = express();

app.use(express.static(__dirname + '/public'))
  .use(bodyParser());

app.get('/login', function(req, res) {
  res.send('log me in!');
});

console.log('Listening on 3000');
app.listen(3000);

然后,我已經上傳到服務器,並使用forever運行app.js文件,即forever start app.js 我可以瀏覽到這是網頁index.html在文件public文件夾。 網址看起來像這樣-http://162.xx.xxx.xxx/project/public/

除了這一行,我的app.js文件看起來與上面的相同:

app.get('http://162.xx.xxx.xxx/project/public/login', function(req, res) {
  res.send('log me in!');
});

當我嘗試導航到登錄網址時,它說:

在此服務器上找不到請求的URL / project / login。 位於http:// 162的 Apache服務器。 。* 。***端口80

誰能告訴我我在做什么錯?

您的apache應該只是傳遞給node的代理:

ProxyPass / http://localhost:3000/

讓您的節點監聽端口3000。您不需要修改任何路由。

然后從瀏覽器訪問您的應用程序,例如: http://xxx.xxx.xxx.xxx/login : http://xxx.xxx.xxx.xxx/login

不錯的閱讀這里: 同一服務器上的Apache和Node.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM