0

I've looked through the many related posts on this but I'm not understanding where I'm going wrong.

What I want is for all http, https and mydomain.com and www.mydomain.com requests to go to https://www.mydomain.com (Similar to this person)

I've checked my SSL certificate and it says it's for www.mydomain.com. I've checked the certificate if I go to mydomain.com or www.mydomain.com and it seems to give the same info, and both seem to be secure (little green lock).

I tried the solution on this post, but got the following error:

Restarting nginx: nginx: [emerg] invalid parameter "443" in /path/nginx/sites-enabled/example:3

The problem I'm having is that users sign in on the www.mydomain.com page and for some reason, they are redirected to the mydomain.com page and they then appear logged out and need to log in again. To be honest, I'm not sure if this is a rails issue or an nginx config issue.

My nginx config file is below:

server {
    listen      80;
    server_name mydomain.com www.mydomain.com;
    return 301 https://www.mydomain.com$request_uri;
}

server {
    listen 443 ssl default;
    server_name www.mydomain.com;
    ...other stuff...
}

I'd really appreciate the help. I'm baffled.

Community
  • 1
  • 1
Mike T
  • 4,747
  • 4
  • 32
  • 52

1 Answers1

0

I think I've solved it and I think my problem was partly rails and partly nginx related.

In rails I had

def default_url_options
  if Rails.env.production?
    {:host => "myapp.com"}

which I changed to

def default_url_options
  if Rails.env.production?
    {:host => "www.myapp.com"}

It helped, but not if people navigated to the myapp.com in the first place.

What fixed it fully was adding another redirect server to my nginx config file:

server {
  listen      443 ssl;
  server_name myapp.com;
  return 301 https://www.myapp.com$request_uri;
}

I hope this helps someone.

Mike T
  • 4,747
  • 4
  • 32
  • 52