3

I have recently migrated a NodeJS app using the Express web server from one hosting provider to another.

Since the switch, all of my req.protocol are returning as HTTP instead of HTTPS. I have configured the SSL certificates on the new host and it is forcing SSL with .htaccess file.

I have always had the trust proxy enabled in my application.

app.enable('trust proxy)';

But, I have tried disabling this but it did not solve my problem.

The request header I am receiving with trust proxy enabled:

{ host: '127.0.0.1:58535',
'upgrade-insecure-requests': '1',
'user-agent':
 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36',
accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*


 /*;q=0.8,application/signed-exchange;v=b3',
'sec-fetch-site': 'none',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
cookie:
 '_ga=GA1.2.1627492895.1565633625; _gid=GA1.2.952960627.1565633625; 
 _hjid=aa79d062-c91e-483d-8654-e2d11b4b8707; _hjIncludedInSample=1',
'if-none-match': 'W/"7d4b-dYhPiTxJki+OCl9FjTfsJQnUkSM"',
'x-forwarded-for': 'X.X.X.X',
'x-forwarded-host': 'example.example.com',
'x-forwarded-server': 'example.example.com',
connection: 'close' }

I am not using NGINX. Why is my app not detecting https as the protocol?

Fuller
  • 191
  • 1
  • 13

1 Answers1

4

After some debugging, it seemed to be a configuration problem with the Apache web server. The web host I was using had some custom configuration which made it difficult to modify the apache config without breaking after services running on the server.

In the end, I decided to learn about Nginx and implement that as a web proxy for my nodeJS application. using app.enable('trust proxy)'; in my code allowed the correct protocol to be passed to the app.

Fuller
  • 191
  • 1
  • 13