PlankTon
PlankTon

Reputation: 12605

Rails/Passenger/Nginx: Redirecting www.domain.com to domain.com (to prevent SSL warning)

I have an SSL certificate on domain.com, but if a user goes to https://www.domain.com, it throws a 'wrong domain' security error.

I'm just wondering on best practice for redirecting all traffic from www.domain.com to domain.com. I tried throwing a rewriterule into passenger, but it still seems to suffer the same problem.

Any ideas appreciated.

Upvotes: 2

Views: 657

Answers (1)

Marco
Marco

Reputation: 4395

Fairly easy to do that with nginx..

server {
  listen 80; 
  server_name www.example.com;
  rewrite ^(.*)$ https://example.com$1 permanent;
}

server {
  listen 80; 
  server_name example.com;

  # etc

That will redirect all requests hitting www.example.com to https://example.com

Upvotes: 1

Related Questions