Dmitry Evgrafoov
Dmitry Evgrafoov

Reputation: 13

Nginx(HTTPS) upstream SpringBoot(http) after success logon chrome redirect to HTTP

SpringBoot App started on 8080

Nginx incoming request on :443 proxy to :8080

start page is ok on https://site/ but after login in SpringBoot chrome redirect to http://site/ (not to https://site/) WHY??? how to FIX

Request URL: https://site/login

Request Method: POST

Status Code: 302

Remote Address: 85.26.149.68:443

Referrer Policy: no-referrer-when-downgrade

RESPONSE HEADERS

HTTP/1.1 302

Server: nginx/1.14.0

Date: Mon, 25 Feb 2019 11:40:17 GMT

Content-Length: 0

Connection: keep-alive

Set-Cookie: JSESSIONID=5196D2D1A7A681BBF713BD3AF61F14FF; Path=/; HttpOnly

X-Content-Type-Options: nosniff

X-XSS-Protection: 1; mode=block

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: 0

X-Frame-Options: DENY

Location: http://site/

And Chrome redirect on after login page page http://site/ WHY ?????

upstream spring_boot_srv {
    server localhost:8080 fail_timeout=0;
}
server {
   listen         80;
   server_name    site;
   return         301 https://$server_name$request_uri;
}
server {
    server_name site;
    listen 443;
    ssl on;
    ssl_session_timeout 5m;
    ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;

    ssl_certificate_key /media/some.key;
    ssl_certificate /media/some.crt;
    ssl_session_cache shared:SSL:10m;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$proxy_port;
        proxy_set_header X-Forwarded-Proto https;
        proxy_redirect off;
        proxy_connect_timeout      240;
        proxy_send_timeout         240;
        proxy_read_timeout         240;
        proxy_pass http://spring_boot_srv;
    }
 }

Upvotes: 0

Views: 637

Answers (1)

IMParasharG
IMParasharG

Reputation: 1905

Add below entry in your application.properties

server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto

For more info

Upvotes: 1

Related Questions