2012-04-28 181 views
0

這裏是我的配置文件: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重定向確實正在工作

+0

您的nginx設置爲服務「moule-a-manque.com」,但您將測試發送到「nibbler.silktide.com」。你需要先排除這個基本問題。 – Dayo 2012-04-28 12:24:08

回答

2

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