LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-09-2017, 05:07 PM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
redirect http to https on nginx as reverse proxy


Hi,
For testing purposes on Ubuntu Server 16 I installed apache which hosts a normal website with varnish as web app cache and nginx as reverse proxy for ssl. I'm using nginx, because varnish doesn't support https. Apache resides on one server, varnish and nginx on another (on the same lan, of course). The reason why I also installed nginx was that I wanted https.
The problem that I have now is that I don't know how to redirect the traffic from port 80 to port 443. I made varnish listen to localhost:80, so that it can be reached only through nginx.

What I tried in nginx conf file was the following:
Code:
server {
	listen 172.31.108.183:80 default_server;
	return 301 https://$host$request_uri;
	listen 443 ssl default_server;
	ssl_certificate /etc/nginx/ssl/nginx_ssl.cert;
	ssl_certificate_key /etc/nginx/ssl/nginx_ssl.key;
	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	server_name my_server_name;

	location / {
	proxy_pass http://127.0.0.1:80;
	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;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
	}


}
But when I try to connect, I get this: ERR_TOO_MANY_REDIRECTS
What am I doing wrong?

Last edited by vincix; 12-09-2017 at 05:08 PM.
 
Old 12-09-2017, 05:40 PM   #2
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Ok, it seems to have worked eventually by simply placing the first two directives (listen 172.31.108.183:80 default_server; and return 301 https://$host$request_uri; ) in a separate server block.
 
  


Reply

Tags
apache 2.4.2, nginx, reverse proxy, varnish



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to Redirect HTTP Traffic to HTTPS in Nginx and Apache LXer Syndicated Linux News 0 03-09-2017 12:54 PM
Trailing slash issue with https to http redirect (Nginx/BitrixVM/CentOS6.5) Akram03 Linux - General 0 02-21-2016 04:10 PM
LXer: Nginx Proxy to HTTP and HTTPS LXer Syndicated Linux News 0 06-03-2013 06:30 PM
BigBlueButton, from http to https reverse proxy Steviepower Linux - Security 3 12-09-2010 07:58 AM
Squid reverse proxy problem (HTTPS to HTTP) RussP Linux - Networking 1 10-02-2008 01:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration