Fixes And Tweaks

This commit is contained in:
Jonatan Rek 2025-01-21 11:34:10 +01:00
parent ca420b5070
commit 4064590b6e
3 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,7 @@
https://github.com/MollardMichael/python-reverse-proxy/tree/master
https://github.com/ItsEcholot/ContainerNursery
https://gist.github.com/bsergean/bad452fa543ec7df6b7fd496696b2cd8
https://docker-py.readthedocs.io/en/stable/
Docker Stack Setup
```yaml

19
app.py
View File

@ -47,26 +47,25 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
if (starting == True):
self.send_response(201)
self.send_header('Content-Type', 'text/plain')
self.send_header('refresh', proxy_host_configuration['proxy_timeout_seconds'])
self.end_headers()
self.wfile.write(str.encode("starting container: {0}".format(container['container_name'])))
conn.close()
self.wfile.write(bytes("starting container: {0} waiting for {1}s".format(container['container_name'], proxy_host_configuration['proxy_timeout_seconds']),"utf-8"))
return
# Open a connection to the target server
conn = http.client.HTTPConnection(proxy_host_configuration['proxy_host'], proxy_host_configuration['proxy_port'])
conn.request(method, self.path, headers=self.headers)
response = conn.getresponse()
#print(response.status)
self.send_response(response.status)
#self.send_header('host', proxy_host_configuration['container_name'])
self.send_header('host', proxy_host_configuration['proxy_host'])
for header, value in response.getheaders():
self.send_header(header, value)
self.end_headers()
if (response.status != 301):
self.wfile.write(response.getcode())
self.wfile.write(response.read())
conn.close()
class ThreadedHTTPServer(ThreadingMixIn, http.server.HTTPServer):
@ -82,5 +81,5 @@ if __name__ == '__main__':
server_address = ('', configuration['proxy_port'])
proxy_handler = ProxyHandler(configuration, docker_client)
httpd = ThreadedHTTPServer(server_address, proxy_handler)
print('Reverse proxy server running on port 8888...')
print('Reverse proxy server running on port {0}...'.format(configuration['proxy_port']))
httpd.serve_forever()

View File

@ -5,4 +5,5 @@ proxy_hosts:
- container_name: wp-dev-db-1
- container_name: wp-dev-wordpress-1
proxy_host: localhost
proxy_port: 80
proxy_port: 80
proxy_timeout_seconds: 10