我有一種情況,我需要將國家代碼添加到nginx中的所有請求中。如何在nginx中爲每個請求添加一個變量?
例如,如果用戶訪問http://example.com:3333/html/about,那麼我應該(使用nginx的重寫)重定向到http://example.com:3333/html/about?country_code=en
我有以下重寫,但我得到「太多的循環」。
rewrite ^(.*)$ http://$host:3333/$1?country_code=en last;
我該如何解決?
nginx.conf
server {
### USA specific config ###
if ($geoip_country_code = US) {
# do something here for USA visitors;
# root path /var/www/html/content/usa/;
rewrite ^(.*)$ http://$host:3333/$1?country_code=en last;
}
}
//謝謝你的回覆。我可以在不檢查請求是否包含國家的情況下執行此操作嗎?如果我按照您的建議進行操作,用戶可以手動發送country_code來覆蓋country_code。 – Moon 2011-05-05 07:31:33