1

I'm trying to setup my nginx server blocks so my domain www.domain.com gets redirected to domain.com. My DNS settings:

A @ 111.111.111.111 
CNAME * domain.com.

And nginx /etc/nginx/sites-available/wordpress

server {
  listen 80;
  server_name www.domain.com;
  rewrite ^(.*) http://domain.com$1 permanent;
}

server {
  listen 80;
  server_name domain.com;

  root /var/www/wordpress;
  index index.php index.html index.htm;

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  error_page 404 /404.html;

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /var/www/html;
  }

  # pass the PHP scripts to FastCGI server listening on the php-fpm socket
  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

When I restart nginx I got the error from a browser This web page has a redirect loop. I tried the solution from Nginx no-www to www and www to no-www but still the same problem.

I just checked the error log /var/log/nginx/error.log:

2015/04/20 14:33:32 [error] 16136#0: *17 client intended to send too large body: 1059663 bytes, client: 86.26.239.246, server: domain.com, request: "POST /wp-admin/async-upload.php HTTP/1.1", host: "www.domain.com", referrer: "http://www.domain.com/wp-admin/upload.php"
2015/04/21 04:42:19 [emerg] 19177#0: unknown directive "listen          80" in /etc/nginx/sites-enabled/wordpress:17
2015/04/21 04:47:08 [alert] 19262#0: *52 open socket #19 left in connection 6
2015/04/21 04:47:08 [alert] 19262#0: *53 open socket #22 left in connection 13
2015/04/21 04:47:08 [alert] 19262#0: aborting

/var/log/nginx/access.log:

31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 184 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 184 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
31.221.76.18 - - [21/Apr/2015:05:21:55 -0400] "GET / HTTP/1.1" 301 184 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"
Community
  • 1
  • 1
DeBoer
  • 551
  • 1
  • 7
  • 16
  • Can you check if you have error logs in your nginx ? – Eric Ly Apr 21 '15 at 08:40
  • Updated my question with error logs. – DeBoer Apr 21 '15 at 09:06
  • Doesn't seem to include errors related to a redirect loop. Do you have new lines in error or access log when you try to refresh your page in your browser ? – Eric Ly Apr 21 '15 at 09:08
  • `unknown directive "listen          80"` i guess you have some weird symbols in this string. Probably non-breakable spaces instead of normal ones. So nginx ignores this config and still uses old one – Alexey Ten Apr 21 '15 at 11:04
  • I thought that was the case, but after I removed the spaces, its still looping, but there is no error in error log. – DeBoer Apr 21 '15 at 11:45

1 Answers1

2

Wordpress itself will redirect you to the domain specified in the settings.

Check if you have configured it with **www.**domain.com

Alfonso de la Osa
  • 1,574
  • 1
  • 14
  • 18