docker:docker-compose:web-upload
Web upload
- docker-compose.yaml
services: upload: build: ./ container_name: upload volumes: - /mnt/images:/var/www/uploads labels: - "traefik.enable=true" - "traefik.http.routers.upload.rule=Host(`upload.example.ca`)" - "traefik.http.routers.upload.entrypoints=websecure" - "traefik.http.routers.upload.tls=true" - "traefik.http.routers.upload.tls.certresolver=letsencrypt" - "traefik.http.services.upload.loadbalancer.server.scheme=http" - "traefik.http.services.upload.loadbalancer.server.port=80" - "traefik.http.services.upload.loadbalancer.responseForwarding.flushInterval=500ms" networks: - web networks: web: external: true
- Dockerfile
FROM php:8.2-fpm-alpine # Install necessary PHP extensions RUN docker-php-ext-install pdo pdo_mysql # Configure PHP settings RUN echo "upload_max_filesize = 10240M\npost_max_size = 10240M\nmax_execution_time = 300\nmax_input_time = 300" > /usr/local/etc/php/conf.d/uploads.ini # Create uploads directory and set permissions for www-data user RUN mkdir -p /var/www/uploads && chown -R www-data:www-data /var/www/uploads && chmod -R 775 /var/www/uploads # Set the working directory WORKDIR /var/www/html # Copy your application files (example) COPY . /var/www/html # Expose the port EXPOSE 9000 # Start PHP-FPM service CMD ["php-fpm"]
- index.php
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['upload'])) { $targetDir = '/var/www/uploads/'; $targetFile = $targetDir . basename($_FILES['upload']['name']); if (move_uploaded_file($_FILES['upload']['tmp_name'], $targetFile)) { echo "✅ File uploaded successfully."; } else { echo "❌ Error uploading file."; } } ?> <!DOCTYPE html> <html> <head><title>Upload</title></head> <body> <h2>Upload a file (up to 10GB)</h2> <form method="POST" enctype="multipart/form-data"> <input type="file" name="upload" /> <input type="submit" value="Upload" /> </form> </body> </html>
- nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; client_max_body_size 10G; sendfile on; keepalive_timeout 65; server { listen 80; root /var/www/html; location / { index index.php; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; try_files $uri $uri/ /index.php; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; } } }
- To generate the password for htpass
openssl passwd -apr1 MyPassword123!
- htpassd
user1:<REMOVED> user2:<REMOVED> user3:<REMOVED>
docker/docker-compose/web-upload.txt · Last modified: by jonathan
