I've been pulling my hair out trying to get this to work. I'm trying to host the Cloud9 SDK (Node.js) app on port 8080 (or whatever port higher than 1024) and use Apache as a reverse proxy over HTTPS to that. It shouldn't be relevant, but I'm also using PM2 to ensure the server comes back up in case of a reboot or something like that.
Now, this works when reverse proxying over HTTP in Apache. It also works when reverse proxying over HTTPS in Nginx. The only reason I don't want to use Nginx is because the same server is also hosting Zoneminder, which is a headache to get working with Nginx (already tried). So I know there's no problem with the Node.js app itself.
I was originally following this article. After that, I did some extensive Googling. However, everything I've tried has not worked. At the root directory (/var/www/html/
) I just have the default Apache landing page. This is where I'm taken instead of to my Node.js app.
This is what I have in my /etc/apache2/sites-available/000-default.conf
file right now:
<VirtualHost *:80>
#ServerAdmin webmaster@localhost
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName example.com
ServerAlias www.example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
#SSLProxyEngine On
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
ProxyPreserveHost On
#ProxyRequests off
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
And in case you're curious, this is what I had in my /etc/nginx/sites-available/default
file:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.com;
ssl on;
# Use certificate and key provided by Let's Encrypt:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_timeout 5m;
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 192.168.1.1 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
root /var/www/html;
# Pass requests for / to localhost:8080:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
Also, I'm not sure if this is relevant, but this is all on a Raspberry Pi 3b.
Ok, I figured out what the issue was. I realized that there were other sites enabled that needed to be removed. I had to
a2dissite 000-default-le-ssl.conf
anda2dissite default-le-ssl.conf
not realizing that apache was looking at those configurations as well. I didn't think about it before because other changes I made to the 000-default.conf file were being reflected. Just not the ProxyPass.