Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Redirects and SSL troubles

$
0
0
Good afternoon all,

I'm having a bit of trouble working out some redirects and stuff in my config. The file in question is for a redirect from my old domain to the new one. There has been some structure change and ssl added.

So what I'm trying to do here is, http of old domain to https of new domain for the root domain www and non-www

and then some specific redirects for specific pages.

The problem is my config either doesn't redirect http://oldomain.com/something at all or it redirect back to just the main page of the new domain.

I'm sure my config has some issues. I'm using lets encrypt and cert-bot for SSL so I think I goofed something up here


I may have went a little crazy with my "removed for security" but I wanted to be safer than sorry.

server {

server_name www.olddomain.com olddomain.com;
# redirects both www and non-www to https
return 301 https://newdomain.com;
if ( $redirect_uri ) {
return 301 https://newdomain.com/$redirect_uri;
}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate REMOVED FOR SECURITY
ssl_certificate_key REMOVED FOR SECURITY
include REMOVED FOR SECURITY # managed by Certbot
ssl_dhparam REMOVED FOR SECURITY # managed by Certbot


}
map_hash_max_size 262144;
map_hash_bucket_size 262144;

map $request_uri $redirect_uri {
/ /;
/about-us-1 /about-us;
/book-now /contact;
/blog /blog;
/blog/... /blog;
/blog/page.. /blog;
/contactus /contact;
}
server {
if ($host = www.olddomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = olddomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
listen [::]:80;

server_name www.olddomain.com olddomain.com;
return 404; # managed by Certbot

}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



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