diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index e41484c..4afc4b3 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -1203,17 +1203,79 @@ def http_server(argv): assert options.force shutil.rmtree(DATA_DIR) + os.makedirs(CONF_DIR, exist_ok=True) + os.makedirs( + os.path.join( + CONF_DIR, + 'conf.d', + ), + exist_ok=True + ) + os.makedirs(DATA_DIR, exist_ok=True) + + with io.open( + os.path.join(CONF_DIR, 'nginx.conf'), + 'w' + ) as f: + f.write(r''' + +events { + multi_accept on; + worker_connections 32; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + expires off; + open_file_cache off; + + log_format main + '[$time_local][$remote_addr, $http_x_forwarded_for, $t1, $server_name]' + '[$request_length,$bytes_sent,$request_time]' + '[$status][$request]' + '[$http_user_agent][$http_referer]'; + + access_log /dev/null combined; + access_log /dev/stderr main; + + include %s/conf.d/*.conf; + + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } +} + ''' % CONF_DIR) + + with io.open( + os.path.join( + CONF_DIR, + 'conf.d', + ), + 'w', + ) as f: + f.write(r''' +server { + listen 80; + charset UTF-8; + client_max_body_sie 2K; + root %s; + %s +} + ''' % ( + DATA_DIR, + location_section, + )) + subprocess.check_call( r''' - mkdir -p $CONF_DIR; - echo "server{listen 80; charset UTF-8; root $DATA_DIR; %s}" > \ - $CONF_DIR/default.conf; - exec nginx -c $CONF_DIR -p $DATA_DIR -g "daemon off;" + exec nginx -c $CONF_DIR/nginx.conf -p $DATA_DIR -g "daemon off;" ''', env=dict( CONF_DIR=CONF_DIR, DATA_DIR=DATA_DIR, - APP_DIR=APP_DIR, + #APP_DIR=APP_DIR, ), shell=True, )