LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2015, 11:41 AM   #1
cbtshare
Member
 
Registered: Jul 2009
Posts: 619

Rep: Reputation: 42
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 .
 
Old 04-27-2015, 02:28 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,902

Rep: Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611
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
       ...
        }
 
Old 04-27-2015, 03:03 PM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 619

Original Poster
Rep: Reputation: 42
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
 
Old 04-28-2015, 01:23 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,902

Rep: Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611
Quote:
Originally Posted by cbtshare View Post
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
 
Old 04-28-2015, 09:08 PM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 619

Original Poster
Rep: Reputation: 42
Quote:
Originally Posted by bathory View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Nginx, Horde, Https, Redirect, This webpage has a redirect loop axetone Ubuntu 0 02-08-2015 11:44 PM
[SOLVED] Nginx X-Accel-Redirect PinoyAko Programming 1 06-12-2011 01:05 PM
nginx rewrite / redirect LMW Linux - Server 4 05-14-2011 12:37 PM
Problem with dynamic url rewrite and redirect in nginx??? gavin2u Linux - Server 3 05-27-2010 11:25 PM
nginx redirect error page cbtshare Linux - Server 0 10-10-2009 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration