2014-10-02 66 views
0

我需要能夠到以下子域名的URL頂級域名重定向爲:Nginx的重寫子域網址頂級域

bie.husky.com/login ----> bie.husky.com

,我有以下我的nginx的配置一段代碼,似乎並沒有消除「/登錄」部分重定向時...

server { 
listen 80; 
server_name bie.husky.com; 

    set $my_var 0; 
    if ($host = 'bie.husky.com/login') { 
    set $my_var 1; 
} 

    if ($my_var = 1) { 
    rewrite^http://bie.husky.com redirect; 
} 


    location/{ 
    root /var/www/bie; 
    index index.html index.htm; 
} 
} 

回答

0

一般來說,最好避免if如果可能:)。參見:IfIsEvil。嘗試使用位置。您可能還想閱讀:http://wiki.nginx.org/Pitfalls

server { 
    listen 80; 
    server_name bie.husky.com; 
    root /var/www/bie; 
    index index.html index.htm; 
    try_files $uri $uri/ =404; 

    location = /login { 
     return 302 $scheme://$host; 
    } 
} 
+0

非常感謝。 – user1896576 2014-10-09 21:05:42

+0

謝謝你的樂趣問題。 – 2014-10-11 11:43:53