#NEWLINE# def nginx_config( settings , locations ) : #NEWLINE# #INDENT# ssl_file_path = ( SSL_FILE_PATH % settings [ 'id' ] ) #NEWLINE# config = '\n        server {\n            listen      [::]:%s;\n            server_name %s;\n            charset     utf-8;\n            client_max_body_size 75M;\n\n        %s\n\n        %s\n        }\n    ' #NEWLINE# ssl = settings [ 'ssl' ] #NEWLINE# if ( bool ( ssl [ 'key' ] ) != bool ( ssl [ 'certificate' ] ) ) : #NEWLINE# #INDENT# raise ValueError ( 'SSL certificate given but not key - need both!' ) #NEWLINE# #UNINDENT# add_ssl = ( '\n    ssl_certificate %s;\n    ssl_certificate_key %s;\n    ' % ( ( ssl_file_path + '.crt' ) , ( ssl_file_path + '.key' ) ) ) #NEWLINE# l = '    location %s {%s}' #NEWLINE# locations = [ ( l % ( path , values ) ) for ( path , values ) in locations . items ( ) ] #NEWLINE# locations = '\n' . join ( locations ) #NEWLINE# http_port = settings [ 'port' ] #NEWLINE# cfgs = ( ( 'http' , http_port , '' , settings [ 'redirect' ] , ssl [ 'port' ] ) , ( 'https' , ( ssl [ 'port' ] and ( '%s ssl' % ssl [ 'port' ] ) ) , add_ssl , ssl [ 'redirect' ] , http_port ) ) #NEWLINE# config_txt = '' #NEWLINE# for ( proto , port , add_config , redirect , other_port ) in cfgs : #NEWLINE# #INDENT# if port : #NEWLINE# #INDENT# l = locations #NEWLINE# if ( redirect is not None ) : #NEWLINE# #INDENT# if ( redirect in ( 'http' , 'https' ) ) : #NEWLINE# #INDENT# l = ( '    return 301 %s://$host:%s$request_uri;' % ( redirect , other_port ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# l = ( '    return 301 %s' % redirect ) #NEWLINE# #UNINDENT# #UNINDENT# config_txt += ( textwrap . dedent ( config ) % ( port , settings [ 'url' ] , add_config , l ) ) #NEWLINE# #UNINDENT# #UNINDENT# return config_txt