-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I have created a small webapp using node/express & I want to host it with apache in Ubuntu. I did it using pm2(process manager for node js)
I have installed below :
- node js (version 6.11.4) ( and npm has version 3.10.10)
- pm2 (version 2.7.2)
- Apache ( version 2.4.18)
Below is the configured virtualhost for it :
( path : /etc/apache2/sites-available/adduser.com.conf)
<VirtualHost *:80>
ServerName adduser.com
ServerAlias www.adduser.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/EastAddUser
<Directory /var/www/html/EastAddUser>
Require local
AllowOverride All
Options Indexes FollowSymLinks
</Directory>
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /East>
ProxyPass http://localhost:8081
ProxyPassReverse http://localhost:8081
</Location>
ErrorLog /var/www/html/EastAddUser/error.log
CustomLog /var/www/html/EastAddUser/access.log combined
Kept node js application content at path : /var/www/html/EastAddUser
Below is the content of app.js file :
(Path : /var/www/html/EastAddUser/app.js)
var express = require('express');
var app = express();
var bodyParser=require('body-parser');
app.use(bodyParser.json())
const fs=require("fs");
app.use(express.static(__dirname));
var xmlOperator = require('./js/xmlOperation.js');
var server = app.listen(8081, function () {
console.log('Node server is running..');
});
app.get('/',function(req,res){
var path=__dirname+'/addUser.html';
res.sendFile(path);
})
app.post('/writeToFile', function(req, res) {
// function writes data in a file
});
Below is the content of package.json file :
(path: /var/www/html/EastAddUser/package.json )
{
"name": "eastadduser",
"version": "1.0.0",
"description": "eastadduser",
"main": "app.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start":"node app.js"
},
"author": "sayali",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"bootstrap": "^3.3.7",
"express": "^4.16.2",
"jquery": "^3.2.1",
"xml2js": "^0.4.19",
"xmlbuilder": "^9.0.4"
}
}
And html file is kept at path /var/www/html/EastAddUser/addUser.html
I have enabled the modules proxy & proxy_http, enabled this site using a2ensite command, started the app.js using pm2 (command : pm2 start app.js)
In browser, when I request to "www.adduser.com/East" , I get error as "The requested URL /East was not found on this server."
when I request for "localhost/East", then the webpage appears but it doesn't calls nodejs functions ( gets error : http://localhost/writeToFile 404 (Not Found) )
Where I did the mistake??