LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Nginx Redirect (https://www.linuxquestions.org/questions/linux-newbie-8/nginx-redirect-4175540894/)

cbtshare 04-27-2015 10:41 AM

Nginx Redirect
 
I have a nginx setup , and there is a redirect in the config to force https, so if a user enters domain.com, they get redirected to https://www.domain.com .

If a user enters https://domain.com, they get an error , because I have no host A record for domain.com, so I want to redirect https to https://www.domain.com when a user enters https://domain.com .

bathory 04-27-2015 01:28 PM

Quote:

If a user enters https://domain.com, they get an error , because I have no host A record for domain.com, so I want to redirect https to https://www.domain.com when a user enters https://domain.com .
You should add "domain.com " in the server_name directive inside the https server definition:
Code:

server {
      listen        443 ssl;
      server_name    www.domain.com domain.com
      ...
        }


cbtshare 04-27-2015 02:03 PM

Thank you for your reply, but that wont work since "domain.com" isnt a entry in DNS , so it will just a return a server not found page.I need a second redirect in https with an if statement so if a user enter https://domain.com, it get redirected to https://www.domain.com but not sure how to write it

bathory 04-28-2015 12:23 AM

Quote:

Originally Posted by cbtshare (Post 5353984)
Thank you for your reply, but that wont work since "domain.com" isnt a entry in DNS , so it will just a return a server not found page.

You said that domain.com->www.domain.com works for plain http.
So it's not a dns issue as domain.com is resolvable for this redirect to work

cbtshare 04-28-2015 08:08 PM

Quote:

Originally Posted by bathory (Post 5354236)
You said that domain.com->www.domain.com works for plain http.
So it's not a dns issue as domain.com is resolvable for this redirect to work

Thank you for your reply.But believe me,
Quote:

nslookup domain.com
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
*** Can't find domain.com: No answer
Quote:

ping domain.com
ping: unknown host domain.com
but when I enter https://domain.com in the browser, it works, its the weirdest thing loll..You are right , it should resolve but it doesn't...anyway I resolved the issue, I entered a host A record domain.com then after I entered www.domain.com , and it worked.

Context:

My problem was than I had www.domain.com as a host A record, and then created a Cname domain.com..But when I go to create a MX record now for domain.com, I get a conflict.And if I tried to create a host A record for domain.com, nothing happens.

So I deleted www.domain.com, then created host A record for domain.com, then created www.domain.com then MX record and its all fine now.

Thank you for your replies.


All times are GMT -5. The time now is 04:33 PM.