We generally use port 80 for http server, and use other port for the Node.js application, ex: localhost:443 for the chat application.
How don’t use the port that could enter the nodejs application. We can use the modules mod_proxy and mod_proxy_http of apache.
Step 1: configuration the file httpd.conf (ex: D:\AppServ\Apache2.2\conf\httpd.conf)
... LoadModule proxy_module modules/mod_proxy.so #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so #LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_http_module modules/mod_proxy_http.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule setenvif_module modules/mod_setenvif.so #LoadModule speling_module modules/mod_speling.so #LoadModule status_module modules/mod_status.so #LoadModule unique_id_module modules/mod_unique_id.so LoadModule userdir_module modules/mod_userdir.so #LoadModule usertrack_module modules/mod_usertrack.so LoadModule vhost_alias_module modules/mod_vhost_alias.so ...
Step 2: configuration the file httpd-vhosts.conf (ex: D:\AppServ\Apache2.2\conf\extra\httpd-vhosts.conf)
Add following lines:
<VirtualHost *:80> ServerAdmin admin@tutorialspots.com ServerName chat.localhost ServerAlias www.chat.localhost ProxyRequests off <Proxy *> Order deny,allow Allow from all </Proxy> <Location /> ProxyPass http://localhost:443/ ProxyPassReverse http://localhost:443/ </Location> </VirtualHost>
However, in some cases, all located in the httpd.conf file.
Step 3: restart apache (httpd service)
Now we can access the link: http://chat.localhost
So, we can deploy multiple websites node.js on one server by using Apache.
1 Comment
How to set hostname for Apache proxy_http | Free Online Tutorials
(October 20, 2018 - 1:22 pm)[…] Read more: Running node.js with apache […]