看到这篇文章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
}
答案 0 :(得分: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)但我建议你避免走那条路。
希望这有帮助。
答案 1 :(得分:0)
如果您在AWS上使用Route 53;那么你不必做任何这样的事情。在Route53本身,我们可以创建一个别名并进行配置,以便将非www重定向到www。