2014-01-11 70 views
0

我怎麼會去這樣做在nginx的虛擬主機改寫爲前綴的域名?Nginx的前綴位置配置

ie:/var/www/site.com/public/ as root with/community in/public文件夾。

變成:瀏覽器中的community.site.com?

location /community { 
    root /var/www/site.com/public/community/; 
    rewrite "community."$document_root$uri.php; 
} 

我以前沒有使用前綴,這是完全錯誤的。我找不到任何教程,所以我來到這裏。

回答

1

你想要做的是被稱爲子域,它是一個單獨的服務器塊,需要在DNS服務器中定義。

server { 
    server_name community.example.com; 
    root /var/www/site.com/public/community/; 
    location/{ 
    # change this to match ur site/framework working technique. 
    try_files $uri $uri/ /index.php$request_uri; 
    } 
} 

這是行不通的,除非你確保host community.example.com會回到你的服務器IP,當然不要忘了重新啓動/重新加載你的nginx的服務。

+0

涼爽,所以它是一種沿着相同的路線,因爲幾乎HTTPS。 – MysteryDev

+0

你可以說這是一個完全不同的域名,就像而不必'example1.com','example2.com',你做'sub1.example.com'和'sub2.example.com' –