0

I am having trouble configuring Apache httpd for ProxyPass and ProxyPassReverse to point one web site to Nodejs.

Per instructions provided by my web hosting company, I tried instructions here. My test site is almost word-for-word these instructions. https://tecadmin.net/apache-frontend-proxy-nodejs/

Then I also found this page saying almost the same thing. https://www.atlantic.net/vps-hosting/how-to-set-up-apache-as-frontend-proxy-server-for-node-js-centos-8/

Then I also reviewed this thread, but again, no help in my instance. Apache and Node.js on the Same Server

I have an index.html file containing

<head>
</head>
<body>
<h1>index.html</h1>
<p>httpd</p>
</body>

I have an app.js file containing

var http = require('http');   
http.createServer(function (req, res) {
    console.log('In create server');
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('<html><head></head><body><h1>app.js</h1><p>node</p></body></html>');
}).listen(3000, "localhost"); console.log('Server running at
http://localhost:3000/');

When I serve up my site, joenobel.com, I get the HTML page no matter what I try.

index.html
httpd

The httpd configurations I have added 2 lines:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

The whole file (with comment lines removed) /etc/httpd/conf/vhosts/webadmin/joenobel.com

Content of /etc/httpd/conf/httpd.conf – no comment lines

ServerRoot "/etc/httpd"

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel debug

<IfModule log_config_module>
    LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%a %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf
Include conf/vhosts-default/
Include conf/vhosts/
Listen 80
Listen 443

Then I added a new config file, /etc/httpd/conf.d/joenobel.conf, which contains:

<VirtualHost *:80>
      ServerName joenobel.com
      ServerAlias www.joenobel.com
      ProxyPreserveHost On
      ProxyRequests On
      ProxyPass / http://localhost:3000/
      ProxyPassReverse / http://localhost:3000/
</VirtualHost>

I tried many things changing the VitualHost to *:443 in case it was an issue with my SSL cert. I have added and removed may options in the .

I have moved ProxyPass and ProxyPassReverse up to the httpd.conf file.

That was the only change that did anything. All my web pages, not just the one in question, joenobel.com were then redirected to app.js. But it wasn’t served up in Nodejs. Instead the text of the .js file was served up like it was HTML. The browser showed:

var http = require('http');

http.createServer(function (req, res) {
    console.log('In create server');
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('<head></head><body><h1>app.js</h1><p>node</p></body></html>');
}).listen(3000, "localhost");
console.log('Server running at http://localhost:3000/');

I am hosting on eapps. I have centos8.

Apache is -

Server version: Apache/2.4.6 (CentOS)

Server built: Apr 2 2020 13:13:23

Node is - v10.24.1

npm is – 6.14.12

package.json is:

{
  "name": "joenobel.com",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node ./app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.3"
  }
}

Thank you,

Joe

Joe Molnar
  • 129
  • 3

0 Answers0