首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为no-www config重定向nginx上的循环。

为no-www config重定向nginx上的循环。
EN

Stack Overflow用户
提问于 2015-04-21 08:13:49
回答 1查看 719关注 0票数 1

我正在尝试设置我的nginx服务器块,以便我的域www.domain.com被重定向到domain.com。我的DNS设置:

代码语言:javascript
复制
A @ 111.111.111.111 
CNAME * domain.com.

和nginx /etc/nginx/sites-available/wordpress

代码语言:javascript
复制
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;
  }
}

当我重新启动nginx时,我从浏览器This web page has a redirect loop中得到了错误。我尝试了Nginx no-www to www and www to no-www的解决方案,但仍然是同一个问题。

我刚刚检查了错误日志/var/log/nginx/error.log

代码语言:javascript
复制
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

代码语言:javascript
复制
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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-21 14:36:00

Wordpress本身会将您重定向到设置中指定的域。

检查您是否用**www.**domain.com配置了它

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29766521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档