Spaces:
Sleeping
Sleeping
Commit
·
af26c89
1
Parent(s):
da84348
Switch from nginx to python HTTP server
Browse files- Dockerfile +9 -13
- nginx.conf +0 -38
- server.py +14 -0
Dockerfile
CHANGED
|
@@ -1,19 +1,15 @@
|
|
| 1 |
-
# Use an official
|
| 2 |
-
FROM
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
chown -R nginx:nginx /var/cache/nginx && \
|
| 7 |
-
chmod -R 755 /var/cache/nginx
|
| 8 |
|
| 9 |
-
# Copy the
|
| 10 |
-
COPY
|
| 11 |
-
|
| 12 |
-
# Copy a custom Nginx configuration file
|
| 13 |
-
COPY nginx.conf /etc/nginx/nginx.conf
|
| 14 |
|
| 15 |
# Expose port 80 to allow external access
|
| 16 |
EXPOSE 80
|
| 17 |
|
| 18 |
-
# Start
|
| 19 |
-
CMD ["
|
|
|
|
| 1 |
+
# Use an official Python image as the base
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Set the working directory
|
| 5 |
+
WORKDIR /app
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Copy the Python script and the HTML file
|
| 8 |
+
COPY server.py .
|
| 9 |
+
COPY index.html .
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Expose port 80 to allow external access
|
| 12 |
EXPOSE 80
|
| 13 |
|
| 14 |
+
# Start the Python HTTP server when the container launches
|
| 15 |
+
CMD ["python", "server.py"]
|
nginx.conf
DELETED
|
@@ -1,38 +0,0 @@
|
|
| 1 |
-
user nginx;
|
| 2 |
-
worker_processes auto;
|
| 3 |
-
|
| 4 |
-
error_log /var/log/nginx/error.log warn;
|
| 5 |
-
pid /var/run/nginx.pid;
|
| 6 |
-
|
| 7 |
-
events {
|
| 8 |
-
worker_connections 1024;
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
http {
|
| 12 |
-
include /etc/nginx/mime.types;
|
| 13 |
-
default_type application/octet-stream;
|
| 14 |
-
|
| 15 |
-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
| 16 |
-
'$status $body_bytes_sent "$http_referer" '
|
| 17 |
-
'"$http_user_agent" "$http_x_forwarded_for"';
|
| 18 |
-
|
| 19 |
-
access_log /var/log/nginx/access.log main;
|
| 20 |
-
|
| 21 |
-
sendfile on;
|
| 22 |
-
keepalive_timeout 65;
|
| 23 |
-
|
| 24 |
-
server {
|
| 25 |
-
listen 80;
|
| 26 |
-
server_name localhost;
|
| 27 |
-
|
| 28 |
-
location / {
|
| 29 |
-
root /usr/share/nginx/html;
|
| 30 |
-
index index.html index.htm;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
error_page 500 502 503 504 /50x.html;
|
| 34 |
-
location = /50x.html {
|
| 35 |
-
root /usr/share/nginx/html;
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from http.server import SimpleHTTPRequestHandler, HTTPServer
|
| 2 |
+
|
| 3 |
+
class MyHandler(SimpleHTTPRequestHandler):
|
| 4 |
+
def __init__(self, *args, **kwargs):
|
| 5 |
+
super().__init__(*args, directory='.', **kwargs)
|
| 6 |
+
|
| 7 |
+
def run(server_class=HTTPServer, handler_class=MyHandler, port=80):
|
| 8 |
+
server_address = ('', port)
|
| 9 |
+
httpd = server_class(server_address, handler_class)
|
| 10 |
+
print(f'Starting httpd server on port {port}...')
|
| 11 |
+
httpd.serve_forever()
|
| 12 |
+
|
| 13 |
+
if __name__ == '__main__':
|
| 14 |
+
run()
|