Quantcast
Channel: NGINX: HTTP to HTTPS redirect not working - Server Fault
Viewing all articles
Browse latest Browse all 3

NGINX: HTTP to HTTPS redirect not working

$
0
0

First time posting here. I've been searching on here for about two days to find a solution to my problem and nothing is working.

I know, there is a ton of posts about this same problem but none of the threads solutions I have came across, have worked so far. I am using NodeJS w/ Angular 5 on an Amazon EC2 instance.

Navigating to https://example.com works fine. The web page loads correctly. But, http://example.com gives me the "Welcome to nginx!" page.

Here is my nginx server config blocks:

server {    listen 443 ssl default_server;    server_name example.com    server_tokens off;    charset utf-8;}... SSL config stuff ...    location / {      proxy_pass http://localhost:8000/;      proxy_http_version 1.1;      proxy_set_header Host               $host;      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  $scheme;      proxy_set_header Proxy "";    }}server {      listen 80;      server_name example.com      return 301 https://$host$request_uri;}
  • Tried changing default_server to the port 80 block
  • Tried using $server_name instead of $host on the redirect line
  • Tried having the port 80 block on top of the port 443 block
  • Checked for syntax errors in the config files (everything is fine)

Also checked for any conflicting files (none that I saw linked to nginx.conf).

curl -I http://example.comHTTP/1.1 200 OKServer: nginx/1.10.3 (Ubuntu)Date: Wed, 18 Jul 2018 04:18:49 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Tue, 31 Jan 2017 15:01:11 GMTConnection: keep-aliveETag: "5890a6b7-264"Accept-Ranges: bytes

As you can see, when I curl http://example.com (not actually example.com), it returns a status of 200 rather than 301. Also, the "Network" tab in Firefox's developer tools, shows a status of 304.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>