1

Update: April 20th 2013, Still no solution found, please help

Looking at my nginx config, the only like that could be the culprit is this:

server {
        listen 80;
        listen [::]:80 ipv6only=on default_server;
        rewrite ^(.*) https://$host$1 permanent;
}

Literally I need 'www' to be redirected to the main domain.

Could this be done in nginx?

I am a bit confused about this matter and Godaddy support is telling me each time something different.

I have forwarded my www domain to the main domain and it doesn't work.

www.domain --> domain.com     Fails

However any other subdomain such as test, can be forwarded to the main domain without any trouble.

test.domain --> domain.com    Ok

Godaddy claims:

or this you will need to setup a www CNAME that maps to @. On your host, you can setup a coded redirect https://domain.com in an index file or .htacess file.

I don't understand how to achieve this.

3

You should first configure your DNS zone as such:

@   IN A <IP ADDRESS>
www IN A <IP ADDRESS>

Using this configuration, anything like www.example.com, and example.com will be resolved to IP ADDRESS which should be your Web server's IP address.

Then, in your Nginx configuration you put this:

server {
  listen 80;
  server_name example.com;
  return 301 https://example.com$request_uri;
}
server {
  listen 80;
  listen 443 ssl;
  server_name www.example.com;
  return 301 https://example.com$request_uri;
}
server {
  listen 443 ssl;
  server_name example.com;
  ...
}
| improve this answer | |
  • Thanks for your reply. In fact I would like to forward only www.mydomain.com to --> mydomain.com. I don't wish to forward all subdomains. You know what I mean? So you suggest to create an A-record with www to my IP? Or a C-name with www to my IP? I have that nginx setting already the way you have described it. – Houman Apr 21 '13 at 18:23
  • @Kave, I've edited my answer. – Spack Apr 21 '13 at 18:49
  • many thanks. But the moment I add this part: the https://example.com doesn't work anymore. But when I remove it it works again. Why? server { listen 80; listen 443 ssl; server_name www.example.com; return 301 https://example.com$request_uri; } – Houman Apr 21 '13 at 19:35
  • @Kave, check the configuration with nginx -t and what's your nginx version? – Spack Apr 21 '13 at 21:05
  • It says: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful I have nginx version: nginx version: nginx/1.2.7 – Houman Apr 21 '13 at 21:26
0

You don't need regex in this task, by the way. Try this config, for example.

server {
        listen *:80 default_server;
        listen [::]:80 ipv6only=on default_server;
        return 301 https://domain.com$request_uri;
}
| improve this answer | |
  • thanks for the tip. I changed that but the actual problem remains. I recon the forwarding of a subdomain falls into Godaddy's responsibility and not my nginx, is that right? – Houman Apr 19 '13 at 15:03
  • I think so. Maybe you should disable any "forwarding" at Godaddy? Just create CNAME record (or records) for each name (such "test.domain.com") pointing to main domain. – cadmi Apr 19 '13 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.