2016-07-19 21 views
0

上我是一個PHP開發人員節點JS應用程序的工作在本地主機,但沒有實際運作的服務器

我有虛擬主機的設置上我的Apache

<VirtualHost sub.domain.com:80> 

     ServerName sub.domain.com 
     ServerAdmin [email protected] 
     DocumentRoot /var/www/subpart/html 

     <Directory /var/www/subpart/html> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
       # Uncomment this directive is you want to see apa$ 
       # default start page (in /apache2-default) when y$ 
       #RedirectMatch ^/$ /apache2-default/ 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

</VirtualHost> 

是我的應用程序。 js文件

var express = require('express'); 
var bodyParse = require('body-parser'); 
var request = require('request'); 
var app = express(); 
// var select = require('./select'); 

app.set('port', 8080); 

app.use(bodyParse.urlencoded({extended: false})); 

app.use(bodyParse.json()); 

app.get('/', function(req, res) { 
    res.send('yelo'); 
}) 
app.listen(app.get('port'), function() { 
    console.log('running on port', app.get('port')) 
}) 

當我運行nodemon app.js我可以http:\\localhost:8080\訪問這個應用程序,但同一應用程序是上傳時編輯生活服務器行爲奇怪https:\\sub.domain.com:8080\錯誤無法連接

我不知道發生了什麼事情,我是一個PHP開發,所有我只需要複製和粘貼文件在服務器上,一切工作查找,但我在nodejs實現方面遇到很多問題

+0

「但同樣的應用程序時,被上傳到服務器住行爲怪異的https:\\ sub.domain.com:8080 \「你只是上傳app.js文件? –

+0

當然不是,我上傳了app.js和package.json並運行npm install :) @KevinL – runningmark

回答

0
  1. 獲取提供2個或更多IP地址的VPS。
  2. 從WHM cPanel中找到菜單項Service Configuration,選擇Apache Configuration,然後點擊Reserved IPs Editor。
  3. 勾選您不希望Apache收聽的IP地址,然後寫下來,以便您可以在下一步中使用它。點擊保存。

安裝的Node.js,並創建這樣一個服務器:

var http = require('http'); 

var server = http.createServer(function(req, res) { 
    res.writeHead(200); 
    res.end('Hello, world!'); 
}); 

server.listen(80, '111.111.111.111'); 

停止浪費你的時間,從來沒有聽那些告訴你的Node.js再次使用mod_rewrite來代理。

NodeJS不能以mod-perl和mod-php的方式作爲Apache模塊使用,所以無法在Apache上運行節點。

我希望這個鏈接將幫助您更多:

Running Node.js in apache?

Apache and Node.js on the Same Server

相關問題