0

在看到这篇文章http://www.ewanleith.com/blog/900/10-million-hits-a-day-with-wordpress-using-a-15-server后,我将服务器从 apache2 更改为 nginx。我不是计算机极客,精明。我按照步骤操作。在那之后,这个网站就完美了,除了一件事:非 www 到 www 的事情。我在网上搜索了如何做到这一点。我尝试了他们说的 modrewrite 东西,但变得更糟了。现在,它被定向到 www,因为我使用 wordpress 并将其设置在常规设置http://www.pageantly.com中。然而,我有静态目录,它是普通的非 www。请查看我在 /etc/nginx/conf.d/ 中的 default.conf 以及上面链接的教程:

server {
server_name pageantly.com www.pageantly.com;
root /var/www/;
listen 8080;
## This should be in your http block and if it is, it's not needed here.
index index.html index.htm index.php;

include conf.d/drop;

 location / {
            # This is cool because no php is touched for static content
try_files $uri $uri/ /index.php?q=$uri&$args;
    }

        location ~ \.php$ {
        fastcgi_buffers 8 256k;
        fastcgi_buffer_size 128k;
        fastcgi_intercept_errors on;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
    }

# BEGIN W3TC Page Cache cache
location ~ /wp-content/w3tc/pgcache.*html$ {
add_header Vary "Accept-Encoding, Cookie";
   } 
[...]
}
# END W3TC Page Cache core

}

4

2 回答 2

1

理想情况下,每个域(包括子域)应该有一个单独的server块。这样一来,您的配置将如下所示:

# Following block redirects all traffic coming to pageantly.com to www.pageantly.com
server {
  server_name pageantly.com;
  listen 8080;

  # Send a 301 permanent redirect to any request which comes on this domain
  return 301 http://www.pageantly.com$request_uri;
}

# Following block handles requests for www.pageantly.com
server {
  server_name www.pageantly.com;
  listen 8080;
  root /var/www;
  [...] # all your default configuration for the website
}

实现此目的的另一种不干净且低效的方法是引入一个if语句,该语句读取域值并相应地分支流以重定向流量(在 pageantly.com 的情况下)或处理请求(在 www.pageantly.com 的情况下),但我建议你避免走那条路。

希望这可以帮助。

于 2012-12-27T14:06:32.540 回答
1

如果您在 AWS 上使用 Route 53;那么你不必做任何这样的事情。在 Route53 本身上,我们可以创建一个别名并进行配置,以便将非 www 重定向到 www。

于 2012-12-28T10:47:27.713 回答