Forward HTTPS traffic thru Nginx without SSL certificate - node.js

I want to use Nginx to expose my NodeJS server listening on port 443.
I don't want to manage the SSL certificate with Nginx. I would rather do that on the NodeJS server using the SNICallback option of https.createServer.
How do I setup the nginx.conf to support this?

You're looking for ssl pass-through. You'll set up your nginx to use TCP load balancing (even if you only have one server it's still thought of as load balancing) and ssl passthrough.
Note that nginx will be unable to access any of the content and that you will lose almost all of the advantages of using a proxy other than the ability to do load balancing.
See these instructions for a specific configuration example.

You can configure nginx to pass the encrypted traffic to the node.js server.
stream {
server {
listen 443;
proxy_pass your.node.js:443;
}
}
Note that you will have no access-log or any other means of access to the data.

Related

How might one set up a reverse proxy that cannot decrypt traffic?

I'd like to have a reverse HTTPS proxy that CANNOT decrypt proxied traffic (ie an HTTPS passthrough/tunnel). The idea is to run this proxy on a VPS and point a domain to it, allowing for the IP address of the origin server to remain unexposed while maintaining end-to-end encryption.
Is this possible? I could probably proxy requests without difficulty since the destination address in that direction is fixed, but proxying responses seems problematic given that the proxy would be unable to read the client IP within an encrypted response.
A potential solution is to have the origin server package the encrypted response and destination address in a request made to the proxy, but I am unsure as to how I might generate the encrypted request without sending it (using node.js, which is the application running on the origin server).
From your question, I got that you want to listen to requests from your VPC server and pass the request to your other server which has to remain unexposed.
This can be configured with the web server which you are using for proxy ( considering AWS allows port forwarding from a VPN server to non-VPN server ).
I prefer doing this with Nginx as it is easy, open-source with less code and more functionality.
There is a concept of load balancing which does the same as you mentioned above.
steps :
Install Nginx and keep it active.
Create a new configuration file in /etc/nginx/sites-enabled
write the below code with modifications:
http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
}
and at the place of srv1.example.com and srv2.example.com add the domain to which you want to redirect requests
Save the file and restart the Nginx
Boom!! it should redirect all incoming requests to your application.

How do I offload from https to http on NGINX?

This question has been asked awhile ago but I am not sure it fits my needs so I want to explain my usage.
First warn, I am a noob.
We have an nginx reverse proxy with a cert. It directs to another nginx app server without a cert (internal communications don't need to be over https). Basically want to off load from https to http internally.
How do we configure it so we hit the app server on port 80? It still appears to be hitting the app server on 443. Getting an ERR_CERT_COMMON_NAME_INVALID error. I assume that it is being thrown by the app server.
In proxy.conf we have set:
proxy_pass http://<app server ip address>
You don't want to redirect, you want to proxy.
It sounds like the certificate on the nginx proxy server is not correct. Specifically that the certificate and the domain don't match
location /some/path/ {
proxy_pass http://www.example.com/link/;
}
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

How is my https:443 server serving http:80 also?

I have a server EC2 instance running in AWS, behind a load balancer which currently doesn’t really do anything since I only have one instance (eventually, I planned on using it to scale and distribute traffic among multiple instances). I’m using Rt53 to point my domain name to the load balancer.
The webserver on the instance uses node(js) and express to serve the site over port 443 (https) with the proper certificates loaded in for encryption/identity/etc, generated by certbot using Let’s Encrypt.
The load balancer is configured like so:
load balancer general config
load balancer target config
So for both ports the load balancer points to the same server, using HTTPS:443, which I figured would force all connections to be encrypted. However, when I type in my URL as http://mydomain.tld it takes me to the webserver with no indication that it’s an https connection.
How is this happening? My nodejs server’s not set up to do anything over port 80, and I thought the load balancer should route all connections to port 443.
80 is the default port for the World Wide web. If you type in google.com:80, it will send you to google normally, while if you try google.com:81, you will not connect.
If you disable 80 port and somebody type http://abc it will show error the best way is to redirect 80 requests to 443
create a redirection from 80 to 443.
app.use(function(request, response){
if(!request.secure){
response.redirect("https://" + request.headers.host + request.url);
}
});
Generally most web server has multiple binding 80 and 443 both.Since if certificate expires you can use 80.
There are several methods of enabling an Apache redirect http to https:
Enable the redirect in the Virtual Host file for the necessary domain.
Enable it in the . htaccess file (previously created in the web root folder).
Use the mod_rewrite rule in the Virtual Host file.
Use it in the . htaccess file to force HTTPS.
https://developer.ibm.com/technologies/node-js/tutorials/make-https-the-defacto-standard/
So if traffic is being forwarded to the same target group that means the same server port will be used for forwarded traffic from the load balancer (ALB).
Requests get mapped to this from the listener and translated to the port mapping for the target group instead.
Therefore, there are two possible practical scenarios that result from this configuration:
client--[HTTP:80]-->ALB--[HTTPS:443]-->EC2
client--[HTTPS:443]-->ALB--[HTTPS:443]-->EC2

How to configure single instance Beanstalk Node.js app without ELB?

I am migrating an app to Beanstalk, and I want to make it clear that the following questions are only about single instance configuration without using Elastic Load Balancer.
Current configuration:
Node.js app running on ports 8081 (HTTP) and 8082 (HTTPS)
Node.js serving static files under /server/public at /
Node.js serving APIs at /api
My basic question is, how do I get incoming traffic to 80 being redirected to 8081? What settings and where do I have to do? Do I need to set up a proxy, such as Nginx, and if I do, what kind of settings do I have to do? I tried going through AWS documentation, but it contains mostly information on setting up Elastic Load Balancer (ELB), and in this case I especially want to set up the system without ELB.
The next question is, what settings and where do I have to do if I wanted to terminate HTTPS on Nginx proxy? I tried the official instructions, but couldn't get them working.
Yeah you can setup nginx as a proxy to pass all requests on port 80 (or 443) to the respective nginx port. Like, :
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://APP_PRIVATE_IP_ADDRESS:8081;
}

HAProxy, Nginx & Node.js SPDY termination

I have a Node.js server using node-spdy to run a SPDY server (with HTTP fallback) in { plain: true, ssl: false } mode.
On top of the Node.js server sits Nginx serving and caching static files and proxying requests to Node.js.
On top of Nginx sits HAProxy balancing the load.
When I first implemented SPDY I just used node-spdy to do the SSL encryption inside Node.js, but know I'd like to use HAProxy to terminate SSL and speak plain SPDY or HTTP inside my network. I'm not sure if Nginx can handle non-encrypted SPDY frames.
Any help configuring Nginx and HAProxy to do just that is very much appreciated. Thanks.
Nginx can handle non-encrypted SPDY frame. Simply use "listen" directive without "ssl" part:
listen 8000 spdy;
"HAproxy (SSL termination) -> Nginx (SPDY) -> your network (HTTP)" setup is described at https://kura.io/2013/07/15/haproxy-nginx-and-spdy-with-ssl-termination-debian-7/

Resources