server { # detect Accept-Language auto redirect to langauge path location = / { # Setup language prefix set $prefix_language $http_accept_language; if ($http_accept_language ~* '^(.+?),') { set $prefix_language $1; } # Setup redirect Schema set $redirect_schema $scheme; if ($http_X_Forwarded_Proto = 'https') { set $redirect_schema $http_X_Forwarded_Proto; } # Setup redirect Host set $redirect_host $host; if ($http_X_Forwarded_Host != '') { set $redirect_host $http_X_Forwarded_Host; } # Setup URL set $lang_url $redirect_schema://$redirect_host; if ($prefix_language ~* 'zh-TW') { return 302 $lang_url/zh-TW/; } if ($prefix_language ~* 'zh-CN') { return 302 $lang_url/zh-CN/; } # Default en-US return 302 $lang_url/en-US/; } } ?>