-
Install the following:
$ sudo a2enmod proxy $ sudo a2enmod proxy_http $ service apache2 restart
-
Navigate to /etc/apache2/sites-available/
$ touch <YOUR DOMAIN NAME>.conf
-
Now add following into /etc/apache2/sites-available/.conf
<VirtualHost *:80> ServerName <YOUR DOMAIN NAME> ProxyRequests Off ProxyPreserveHost On ProxyVia Full <Proxy *> Require all granted </Proxy> <Location /> ProxyPass http://localhost:<YOUR PORT>/ ProxyPassReverse http://127.0.0.1:<YOUR PORT> </Location> </VirtualHost>
-
Enable the site
$ sudo a2ensite <YOUR DOMAIN NAME>.conf
-
Add domain to host
$ sudo gedit /etc/hosts 127.0.0.1 <YOUR DOMAIN NAME>
-
Restart apache server
$ sudo service apache2 reload
-
Navigate to your nodejs app
$ cd ~/path/to/your/nodeapp/app.js
-
Add following in the app.js file:
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Node.js is running from site1.\n'); }).listen(8080); console.log('Server running at http://127.0.0.1:8080/');
-
Goto the terminal, and type
$ cd ~/path/to/your/nodeapp/ $ node app.js
-
In browser type
<YOUR DOMAIN NAME>
-
Notifications
You must be signed in to change notification settings - Fork 0
rupachowrasia/node-hosting-with-apache
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Configuring Apache to Serve NodeJS Application
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published