Refactor write_nginx_conf method