I'm using Nginx to
redirect all HTTP requests to HTTPS
in my spring boot application.This is the nginx configuration that i'm using,with that i was able to redirect all requests to Https but when i do it i get the status code returned correctly but it doesnt have the status code name anymore.if i remove nginx and run spring boot application alone i can get the http status with its code name and code.
server { listen 80 default_server; listen [::]:80 default_server; server_name _ ; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if ( $http_x_forwarded_proto != 'https' ) { return 307 https://$host$request_uri; } location / { proxy_set_header X-Forwarded-Proto http; proxy_pass http://localhost:7070; expires -1; } }
what am i doing wrong in here should i use proxy_redirect instead of proxy_pass, or am i missing anything in here.that'd be great if you can help.
1 Answers
Answers 1
In the same config file
listen on 80 to redirect req to https (443)
server { listen 80; listen [::]:80; server_name your_url.com www.your_url.com; return 301 https://your_url.com$request_uri; }
listen on 433
server { listen 443 ssl default_server; listen [::]:443 ssl default_server; location / { # proxy pass to your app proxy_pass http://localhost:7070; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
This is the way I do it, and works perfectly for me, cheers!
0 comments:
Post a Comment