Corrected inconsistent hash iteration order: resulted in frequent nginx restarts

Inconsistent hash iteration order in the templates caused nginx to unpredictably restart when using $location_cfg_prepend or $location_cfg_append.

By adding ".sort_by {|key,value| key}.each do" to keep the hash sorted, the iteration order remains consistent and we avoid having config file content being changed frequently, which results in notifying the nginx service to restart.