Nginx 的 map 設定

Nginx 的 Map 是用在需要設定一個變數給設定檔使用的功能,在Magento的多站裡使用map的功能,可以更好管理設定檔。
 
Map的格式
map $var1 $var2 {
字段1 字段2
}
$var1: 用來與字段1做匹配的變數
$var1: 當匹配符合會將字段2的值存到$var2
字段1: 用來與$var1做匹配
字段2: 同一列的字段1匹配成功時,會將字段2的內容存到$var2
Map的範例
http {
map $http_host $magesite {
       store1.magento.com base;
       store2.magento.com nz;
       store3.magento.com base;
       store4.magento.com nz;
}
server {
       listen 8080;
       server_name   store2.magento.com;
location /hello {
default_type text/plain;
echo the store of magento is : $magesite;
}
}
}
 
$http_host為用戶端的請求url,然後跟字段1做匹配,假如請求的url為store2.magento.com,則會匹配到store2.magento.com nz 這一行,這時候會將nz指派給$magesite變數,然後看下面:
location /hello {
default_type text/plain;
echo the store of magento is : $magesite;
}
 
代表著進到store2.magento.com/hello這個網站的時候會印出 the store of magento is : nz;
在做Nginx設定的時,常常會有很多重複的字串,這時候可以把字串指派到變數裡使用,在管理上就會便利許多。
以上是這次關於如何在Nginx做map設定的分享,更多電商營運相關知識,別忘訂閱歐斯瑞電子報,以及幫我們的Facebook粉絲專頁按讚唷!
 
更多Magento相關文章請看: Magento教學導覽
延伸閱讀:
如何在Nginx環境下設定Magento Multi-website
 
	 
			 
			 
			 
			 
			 
			
我要留言