LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 10:41 AM   #1
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

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, 01:28 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 02:03 PM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

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, 12:23 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 08:08 PM   #5
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

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



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 10:44 PM
[SOLVED] Nginx X-Accel-Redirect PinoyAko Programming 1 06-12-2011 12:05 PM
nginx rewrite / redirect LMW Linux - Server 4 05-14-2011 11:37 AM
Problem with dynamic url rewrite and redirect in nginx??? gavin2u Linux - Server 3 05-27-2010 10:25 PM
nginx redirect error page cbtshare Linux - Server 0 10-10-2009 01:30 PM

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

All times are GMT -5. The time now is 12:33 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
Open Source Consulting | Domain Registration