0

I'm a php developer

I've a setup of virtual host on my apache

<VirtualHost sub.domain.com:80>

        ServerName sub.domain.com
        ServerAdmin localhost@domain.com
        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>

here is my app.js file

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'))
})

when i run nodemon app.js i can access this application on http:\\localhost:8080\ but the same application is when uploaded to live server acts weird https:\\sub.domain.com:8080\ with error unable to connect

I've no idea what is going on, i'm a php dev and all i had to do was just copy and paste file on server and everything worked find, but i'm having a lot of issue with nodejs implementation

runningmark
  • 738
  • 4
  • 13
  • 32
  • "but the same application is when uploaded to live server acts weird https:\\sub.domain.com:8080\" are you just uploading the app.js file? – Kevin L Jul 19 '16 at 15:29
  • of course not, i uploaded app.js and package.json and ran npm install :) @KevinL – runningmark Jul 19 '16 at 15:34

1 Answers1

0
  1. Get a VPS that offers 2 or more IP addresses.
  2. From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.
  3. Tick the IP address you DON'T WANT Apache to listen to, and write it down so you can use it in the next step. Click Save.

Install Node.js, and create a server like this:

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');

Stop wasting your time and never listen to those telling you to use mod_rewrite to proxy Node.js again.

NodeJS is not available as an Apache module in the way mod-perl and mod-php are, so it's not possible to run node "on top of" Apache.

I hope this link will help you more:

Running Node.js in apache?

Apache and Node.js on the Same Server

Community
  • 1
  • 1