Cannot POST to express server from domain with SSL on it - node.js

I have an existing ssl certificate through LetsEncrypt for my domain. On the same server as my site I have an express app running at port :8080. Before adding the SSL to the domain I was able to make requests to http://domainname:8080.com. Now that the domain making the requests is https it obviously can't make those requests. If I instead make requests to https://domainname:8080.com, I get no response and instead get a timeout error.
I have attempted to curl -X -POST on the server manually and it returns (35) gnutls_handshake() failed: The TLS connection was non-properly terminated. If I however run the same command pointing to the non https domain it executes correctly. I also tried installing the https modules for express and pointing it to the same certs I'm using for the domain. For all my effort I cannot get this to work. What am I missing here? I want to make requests to a port on the same server that is serving my app.

Setup a reverse proxy in my nginx site config from the domain to the ip address the express server was running on. This solved all the issues I was having.

Related

How to make my Ubuntu/Apache2 (Using Nodejs and Expressjs) server use the server's localhost instead of the user's localhost?

I'm new to Ubuntu and Apache.
When I CRUD through Express, instead of using the serverĀ“s localhost, server/browser will use my computer's localhost.
If I turn off Express server in localhost, the server's get, post and delete don't work, and I can't seem to find a way to use the server's localhost instead of my computer's.
I've also tried sending my requests to:
http://localhost:8383/decrypted
http://127.0.0.1:8383/decrypted
The routes above throw an error as they are http and server is https.
https://example.com/8383/decrypted
The route about throws error connection refused
https://example.com/8080/decrypted
I tried adding a virtualhost in 8080 and routing it through apache to 8383, but shows the same error as above, connection refused.
How can I make the server use its localhost instead of the user's localhost?

http to https url in AWS Beanstalk single instance environment

I deployed my NodeJS/Express app on AWS Beanstalk. The current config is :
Environment type: single instance
EC2 instance type: t2.micro
Node.js version: 10.15.0
No load balancer
Proxy server : Nginx
When deployed it gives me a URL http://<app-name>.<server-location>.elasticbeanstalk.com/
I tested (using Postman) my authenticate API with the URL - http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate and it gives me the status code of 200 OK and is working fine.
When I use HTTPS instead of HTTP it doesn't work as expected. In postman I get below error:
There was an error connecting to https://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate
I have my frontend deployed on netlify and when I trigger the same request from my Web application it gives me below error :
The page at 'https://<app-name>.netlify.com/login' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate'. This request has been blocked; the content must be served over HTTPS.
I understand that since my request is coming from https I need to have my backend configured to have https listener. I am not sure as to how I can accomplish this in AWS Beanstalk where I don't have a Load balancer and my env type is a single instance.
I am new to AWS. Appreciate your help. Thanks!
You'll need to add an .ebextension config file to:
Allow 443 traffic in your Security Group
Install the ssl package
copy the certificates from the application package to the ssl dir. (certificates can be created in the certificate manager) or paste them in the config file
edit nginx config
Here is an example
https://edwardsamuel.wordpress.com/2015/07/17/enable-https-and-http-redirect-on-aws-elastic-beanstalk/

Run nodejs app through HTTPS

I have a node app that is setup on SSH by running node osjs run --hostname=dc-619670cb94e6.vtxfactory.org --port=4100.
It starts at http://dc-619670cb94e6.vtxfactory.org:4100/ without problems, but instead I want to serve it through HTTPS https://dc-619670cb94e6.vtxfactory.org:4100/ , where I receive an error ERR_CONNECTION_CLOSED.
If I use the port I'm unable to reach it with https, but https://dc-619670cb94e6.vtxfactory.org/ is accessible.
How can I serve the port 4100 through htttps?
Thanks.
This is an implementation detail of OS.js. Their docs recommend setting up a reverse proxy for servers. Doing this will give you more control over SSL and ports, like you want
https://manual.os-js.org/installation/

Node not working properly

any ideia why my node only runs in http? The node keeps running but if you put https in browser the node will not work properly, as it only works properly on http,
Configuring Nginx and SSL with Node.js for HTTPS
Please go through the below link and follow all steps
Link
Note: It is mandatory to have Domain Name forwarding request to your working Node IP Address

Why are HTTP curl/Postman requests to a HTTPS server working? (Node, AWS)

I've set up a HTTPS Node server on AWS EC2 which runs on port 4443 and set up Nginx to redirect requests(port 443).
https.createServer(options, app).listen(4443, function(){
console.log("https server started at port 4443");
});
The HTTPS server is working fine, I get a secure connection on browsers and
curl https://mydomain/apiroute works
Now, when I do
curl http://mydomain/apiroute the requests still work. The same goes for Postman.
I know that I can redirect all HTTP traffic to HTTPS using something like 301 redirects but my question is, why does the server respond to HTTP API calls inspite of there being no "HTTP" server?
Additionally, I use a letsencrypt generated certificate.

Resources