2013-09-12 5 views
1

У меня есть приложение, которое прослушивает порт 8080 Я хочу передать все: 80 Подключение к: 8080, а затем до: 80 для смотрите страницу PHP в веб-сервереRun Nodejs сервер с Apache на порту 80

Это мой app.js

var http = require('http'), 
    sockjs = require('sockjs'), 
    fs  = require('fs'), 
    url = require('url'), 
    path = require('path'), 
    mime = require('mime'), 
    zlib = require('zlib'), 
    shared = require('./js/shared.js'); 

var compressible_cache = {}; 

function static_server (request, response) { 

    function get_filepath(request, response, callback){ 
    function response_not_found(response){ 
     response.writeHead(404, {'Content-Type': 'text/plain'}); 
     response.write('404 Not Found'); 
     response.end(); 
    } 

    var uri = url.parse(request.url).pathname; 
    var filepath = path.join('/var/www', 'webroot', path.normalize(uri)); 
    fs.exists(filepath, function(exists){ 
     if(!exists){ 
     response_not_found(response); 
     }else{ 
     if(fs.statSync(filepath).isDirectory()) filepath = path.join(filepath, 'index.html'); 
     fs.exists(filepath, function(exists){ 
      if(!exists){ 
      response_not_found(response); 
      }else{ 
      callback(filepath); 
      } 
     }); 
     } 
    }); 
    } 

    function compression_type(request, mimetype){ 
    const compressible_mimetypes = {'application/javascript': true, 'text/html': true, 
            'text/css': true, 'model/vnd.collada+xml': true }; 
    if(!(mimetype in compressible_mimetypes)) return null; 
    var accept_encoding = request.headers['accept-encoding']; 
    if(!accept_encoding) return null; 
    if(accept_encoding.match(/\bdeflate\b/)) 
     return 'deflate'; 
    else if(accept_encoding.match(/\bgzip\b/)) 
     return 'gzip'; 
    else 
     return null; 
    } 

    function consume_stream(stream, callback){ 
    var buffer = new Buffer(0); 
    stream.resume(); 
    stream.on('data', function(data){ buffer = Buffer.concat([buffer, data]); }); 
    stream.on('end', function(){ callback(buffer); }); 
    } 

    function send_compressed(response, mimetype, compression, data){ 
    response.writeHead(200, {'Content-Type': mimetype, 'Content-Encoding': compression }); 
    response.end(data); 
    } 

    get_filepath(request, response, function(filepath){ 
    var mimetype = mime.lookup(filepath); 
    var compression = compression_type(request, mimetype); 
    if(!compression){ 
     response.writeHead(200, {'Content-Type': mimetype}); 
     fs.createReadStream(filepath).pipe(response); 
    }else{ 
     if(!(filepath in compressible_cache)) compressible_cache[filepath] = {}; 
     if(!(compression in compressible_cache[filepath])){ 
     var compressor = (compression == 'deflate') ? zlib.createDeflate(): zlib.createGzip(); 
     consume_stream(fs.createReadStream(filepath).pipe(compressor), function(data){ 
      compressible_cache[filepath][compression] = data; 
      send_compressed(response, mimetype, compression, data); 
     }); 
     }else{ 
     send_compressed(response, mimetype, compression, compressible_cache[filepath][compression]); 
     } 
    } 
    }); 
} 
//HERE A LOT OF FUNCTION TATH DON'T TO KNOW NEED 
var app = http.createServer(static_server); 
comms.installHandlers(app, {prefix: '/comm'}); 
app.listen(8080); 

Это мой httpd.conf

NameVirtualHost *:80 
<VirtualHost *:80> 
    ServerName moneycheckers.net 
    ServerAlias www.moneycheckers.net 
    DocumentRoot /var/www/html 
    ProxyRequests Off 
    ProxyPreserveHost On 
    <Location /> 
     ProxyPass http://localhost:8080/ 
     ProxyPassReverse http://localhost:8080/ 
    </Location> 
</VirtualHost> 

Но когда я иду www.mywebsite/page.php я получаю "404 Not Found" Поскольку сервер выполняет приложение, а не apache Я хочу, чтобы сервер выполнял apache, но отправлял информацию о клиенте в app.js

ответ

0

Возможно, вам также понадобится сделать виртуальный хост для вашего порта 8080?

0

Ваша конфигурация vhost выглядит хорошо, вы добавили URL-адрес в свой файл hosts?

Смежные вопросы