Welcome! Log In Create A New Profile

Advanced

NGINX as Reverse Proxy works for HTTPS but not with HTTP

Posted by kashyapvirgo 
NGINX as Reverse Proxy works for HTTPS but not with HTTP
December 11, 2018 03:10PM
Guys,

I am very new to nginx and trying to use it as a reverse proxy for my apache/php application that is behind internal load balancer with IP : 10.0.1.4
I am trying to redirect traffic that comes to my NGINX reverse proxy to the internal load balancer's IP.

When i use HTTPS configuration in proxy.conf , it works fine with self signed cert errors

but when I use non SSL version of proxy.conf and try to hit nginx reverse proxy on port 80, it does not work.

following are the contents of my file. Please help me if you can. i spent a lot of time before posting the issue here. i could not get it working.

My environment : Red Hat Enterprise Linux Server release 7.6 (Maipo) on Azure
nginx version: nginx/1.15.5
Nginx.Service : Active and Running

-------------------------------------------------------------------------------------------
NGINX.CONF
-------------------------------------------------------------------------------------------

[root@webserver1 nginx]# vim nginx.conf
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

-----------------------------------------------------------------------------
WORKING HTTPS PROXY.CONF -- THIS WORKS
-----------------------------------------------------------------------------
:[root@webserver1 nginx]# cd conf.d/
[root@webserver1 conf.d]# vim proxy.conf

server {
listen webserver1:443;


ssl on;
ssl_certificate /etc/nginx/ssl/proxy.pem;
ssl_certificate_key /etc/nginx/ssl/proxy.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 2m;

location / {
proxy_pass http://10.0.1.4:80;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}

----------------------------------------------------------------------------------------------------------
NOT WORKING PROXY.CONF for HTTP access ONLY
-------------------------------------------------------------------------------------------
server {
listen 80 default_server;
location / {
proxy_pass http://10.0.1.4:80;
}
}

---------------------------------------------------------------------

When it works i am hitting the URL : https://webserver1 or https://10.0.1.5

I am trying to get URL : http://webserver1 or http://10.0.1.5 to work.

Any help is appreciated .

Thanks
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 118
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready