0

So I have a node.js server like http://someIp:3000. Is it possible to install https on this without getting a domain name and running on port 80? The reason I'm asking this question is that I have a php website running on https and when I try to communicate with my node server it complains that you requested an insecure XMLHttpRequest endpoint.

Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63

2 Answers2

0

Yes it is:

var fs = require('fs');
var https = require('https');
var express = require('express');
var socket = require('socket.io');
var storage = require('node-persist');
var port = 8443;

var sslOptions = {
  pfx: fs.readFileSync('cert/cert.pfx'),
     passphrase: "Node2015"
};

var app = express();

app.all('/*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, *');
  next();
});

var server = https.createServer(sslOptions, app);
Joakim M
  • 1,793
  • 2
  • 14
  • 29
  • cert.pfx is custom made? because I know godaddy doesn't let you get ssl on http://ip:3000. my php server is using verified ssl – Hirad Roshandel Oct 19 '15 at 06:28
  • Yes. It is custommade. You should be able to use your verified ssl-certificate too! – Joakim M Oct 19 '15 at 06:32
  • there are on 2 different servers so I cannot use the verified one for both. Also I don't think the custom made ssl is acceptable but i'll try – Hirad Roshandel Oct 19 '15 at 06:33
  • Look at this one: http://stackoverflow.com/questions/8355473/listen-on-http-and-https-for-a-single-express-app – Joakim M Oct 19 '15 at 06:38
0

You should either configure the webserver running PHP to connect to your NodeJS Server using a reverse proxy (then both will be accessible through the same hostname and port) or configure NodeJS with the correct CORS headers.

I think in your scenario the reverse proxy will be easier to configure. Configure NodeJS to only allow localhost https connections and then configure your Apache to proxy requests coming in.

Marged
  • 10,577
  • 10
  • 57
  • 99