1

My nginx configuration works great until I add a redirect that forces HTTPS. The working config before the redirect is is:

server {
  listen 80;
  listen 443 default_server ssl;
  server_name my-domain.com www.my-domain.com;
  client_max_body_size 5M;

  location / {
    proxy_pass http://localhost:3000;
  }
}

I'm running an app on port 3000 of the server, and I want to serve it up at my domain on port 80 and port 443 (http and https). However, I also want to redirect users to HTTPS when they try to access it over HTTP. I used this answer to set that up:

server {
  listen 80;
  server_name my-domain.com www.my-domain.com;
  client_max_body_size 5M;
  return 301 https://$server_name$request_uri;
}

server {
  listen 443 default_server ssl;
  server_name my-domain.com www.my-domain.com;
  client_max_body_size 5M;

  location / {
    proxy_pass http://localhost:3000;
  }
}

but this causes a redirect loop. I admit that I'm relatievly new to nginx, so if anyone could put me to resources that could explain this, then it would be much appreciated. My guess is that it has to do with the use of location and/or proxy_pass, but digging through the docs didn't lead to any deeper insights.

Another thing to note is that this app is being sent through CloudFlare.

1

1 Answer 1

0

This is resolved. I stuck to my original nginx config and used a CloudFlare page rule to force HTTPS.

The rule used was:

http://*gistbook.io/* => always use HTTPS

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .