server {
listen 80;
server_name domain.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
This is actually the best answer. You should avoid if's if you canUsing if's in NGINX config is not good: http://wiki.nginx.org/Pitfalls#Taxing_Rewrites
server {
listen 80;
server_name domain.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
Can't agree more. As I start my journey with a simple LEB, you guys are a load of help.But other than that, you did the right thing in coming back and posting the solution that worked for you. I wish everybody did that.
Because that works , I was searching for the answer , I got that , posted that in my blog and i shared it here. Just it. I don't need linkbacks . If any admin/moderator has some question about my act too then i will just remove it.I'm perplexed as to why the best answer is your own blog post. And don't say the posts above yours didn't work as the extra 'scheme' check you out in the post does nothing. Is this a new form of rep back linking?
is the canonical answer form as it avoids regex altogether and uses the builtin request string. Raymii's answer is still usable and better than yours - and Sunshine went so far as to educate you why ifs are bad.return 301 http://www.domain.com$request_uri;
I marked which worked for me . Thats all.So just for reference to anyone else searching... your own-post has several issues (pointed out by everyone else on this board):
1) Uses "if" in a nginx config where it really doesn't even need it. Your $scheme will always be 'http' give its location in the :80 server config.
2) Your use of a heafty regex capture goes against almost all known examples.
5n1p's answer of
is the canonical answer form as it avoids regex altogether and uses the builtin request string. Raymii's answer is still usable and better than yours - and Sunshine went so far as to educate you why ifs are bad.
You're more than within your rights to select yourself as the 'best answer', but there's something odd about it no matter your reasoning, especially when its so far off the mark.
Both 'return 301' and 'rewrite .... permanent' in the above examples will barf out the same 301 redirect http code. The only difference between the two is that the 'return' examples don't need the extra regex.Rewrite or redirect better? For now i'm using redirect.
server {
listen 192.168.0.1:443 ssl spdy;
server_name www.example.com;
.
.
.
[SSL Certtificate Code]
.
.
.
}