Welcome! Log In Create A New Profile

Advanced

HTTPS Redirect

Posted by arky 
HTTPS Redirect
May 02, 2022 03:09AM
The top level server redirect from http to https doesn't work with the following nginx site configuration

Testcase:
1) Open the browser http://example.org
2) The server doesn't redirect to https://example.org

Adding 'return 301 https://$host$request_uri;' has no effect either.


```
upstream backend {
server localhost:8080;
}
upstream frontend {
server localhost:3000;
}


server {
listen 80;
server_name localhost
vagrant;

location ~ /\+\+api\+\+($|/.*) {
rewrite ^/\+\+api\+\+($|/.*) /VirtualHostBase/http/$server_name/Plone/++api++/VirtualHostRoot/$1 break;
proxy_pass http://backend;
}

location ~ / {
location ~* \.(js|jsx|css|less|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
expires +1y;
proxy_pass http://frontend;
}
location ~* static.*\.(ico|jpg|jpeg|png|gif|svg)$ {
add_header Cache-Control "public";
expires +1y;
proxy_pass http://frontend;
}

location ~ /(@@download|@@images|@@ical_view) {
rewrite ^(.*) /VirtualHostBase/http/$server_name/Plone/VirtualHostRoot$1 break;
proxy_pass http://backend;
break;
}

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_redirect http:// https://;
proxy_pass http://frontend;
}
}





```



https://github.com/ericof/training-deploy-project/blob/main/ansible/files/nginx/default
Attachments:
open | download - default (1.2 KB)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready