0

I have a working website (https://example.com/ ) with PHP, apache2, MySQL in ubuntu 18

I do want to create API (https://example.com/api) using nodejs and express js. So we have installed node js and started working on making a Nodejs app inside /api ( on same ubuntu machine ). we could easily access our API without https (http://example.com/api) but when we try with https (https://example.com/api) it is not working at all. And the main website is still working fine with https.

I do not understand why https is not working for /api folder but it is working for the whole website. I have tried some other solution but nothing is working for me. Because many solutions are recommending to use Nginx. But I am not familiar with Nginx at all and we have a lot of custom configuration for apache2 and no idea how we could archive that.

Here is the simple code which is written on index.js inside /api folder

app.get('/',function (req, res, next) {

    res.json({
        'success': {
            'message': 'done'
        }
    });
});

Any help will be appreciated. Thanks

Edit:

I tried with the answer from this question (Enabling HTTPS on express.js) and it is working with https, now I am concern about, is it the right way to implement SSL ? or we should try to get it done with apache config file

Ganesh
  • 1,136
  • 13
  • 25

1 Answers1

0

HTTPS Should be enabled on your HTTP Server Apache2, not on NodeJS. You should then use proxypass to proxy the /api into your application (that will be standing on some port - block the port from directly communicating from outside the server). Then all clients will use HTTPS to connect to the Apache2 itself, but apache2 will use normal connection with node - therefore you have ssl for outside usage and users, but no excessive overhead for node itself.

Examples: https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

Seti
  • 2,169
  • 16
  • 26