nginx的301重定向不工作
问题描述:
这里是我的配置文件:nginx的301重定向不工作
server {
listen 80;
server_name moule-a-manque.com;
access_log /var/log/nginx/myvps.com.access.log;
error_log /var/log/nginx/myvps.com.error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
expires off;
rewrite http://www.moule-a-manque.com http://moule-a-manque.com permanent;
location/{
root /var/www/mom;
index index.html index.php;
}
我认为应该工作,但是当我在http://nibbler.silktide.com/reports/moule-a-manque.com检查它似乎是说,重定向不工作。
我正在做这件事吗?如果是的话如何确保301重定向确实正在工作
答
nginx中的重写指令只匹配url的路径部分,而不匹配主机名。它看起来像你试图迫使无www的,它是通过使用另一台服务器{}实现:
server {
server_name www.moule-a-manque.com;
rewrite^http://moule-a-manque.com$request_uri? permanent;
}
server {
listen 80;
server_name moule-a-manque.com;
access_log /var/log/nginx/myvps.com.access.log;
error_log /var/log/nginx/myvps.com.error.log;
client_max_body_size 4M;
client_body_buffer_size 128k;
expires off;
root /var/www/mom;
index index.html index.php;
}
此外,它通常最好设置你的根的位置之外。请参阅http://wiki.nginx.org/Pitfalls。
+0
非常感谢您的工作 – silkAdmin 2012-04-28 14:23:59
您的nginx设置为服务“moule-a-manque.com”,但您将测试发送到“nibbler.silktide.com”。你需要先排除这个基本问题。 – Dayo 2012-04-28 12:24:08