How to configure nginx to listen for plain HTTP but proxy_pass to HTTPS address?
December 18, 2020 10:08AM
How to configure nginx to listen for plain HTTP but proxy_pass to HTTPS address?

In my Nginx config file, this is my preconfigured file content:

http {
server {
listen 8080 default_server;
return 301 https://$host$request_uri;

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /usr/share/nginx/html;

ssl_certificate "/etc/nginx/cert/";
ssl_certificate_key "/etc/nginx/cert/";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {

proxy_intercept_errors on;
error_page 404 /404.html;
location = /404.html {
root /etc/nginx/;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /etc/nginx/;
This configures listening on 8080 port and redirecting to 443 port for over SSL to origin server (proxy_pass) and works fine.

But, however, in my this scenario:
browser ---[apache:80/443 --- nginx(reverse-porxy):8080] --- origin server:443,

apache: listen 80/443
nginx: listen 8080
origin server: listen 443

I want nginx listen a plain HTTP port (8080), but as a client over SSL to connect origin server. In the node, there is Apache listening on 443, so I don't want assign additional SSL port for nginx.

In my scenario, how to setup the configuration file?



I mean, I am looking for a way of configuring the nginx.conf
it just listen 8080 for HTTP request and as a *client* over SSL of origin HTTPS server. so my nginx only listen 8080 one port. whether this is viable?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 68
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready