From 30f64a8a3ac599512542d7ed2a9fe15ec065db35 Mon Sep 17 00:00:00 2001 From: Fabian <50114802+fabalexsie@users.noreply.github.com> Date: Fri, 31 May 2024 15:26:52 +0200 Subject: [PATCH] run http and https on the same port --- README.md | 26 +++++++++++++++++++++++--- compose.yml | 3 +-- ssl.conf | 8 ++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9fc323f..7981d4f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,18 @@ Example execution: +```bash +docker run --rm -it \ + -v "$PWD/uploads:/var/www/html/uploads" \ + -e HOSTIP=$(hostname -I | awk '{print $1}') \ + -p 1337:443 \ + ghcr.io/fabalexsie/simple-web-upload-docker:master ``` -docker run --rm -it -v "$PWD/uploads:/var/www/html/uploads" -p 1337:80 ghcr.io/fabalexsie/simple-web-upload-docker:master -``` + +> `HOSTIP` can also be set manually to the local ip for example 192.168.X.X +> It is only needed for the self signed certificate, when reaching the webapp via https (necessary for PWA). + +> The webserver is visible on host port 1337 with http and https (self-signed). or via compose.yml: @@ -13,9 +22,11 @@ services: app: image: ghcr.io/fabalexsie/simple-web-upload-docker:master ports: - - "1337:80" # webserver is visible on host port 1337 + - "1337:443" # webserver is visible on host port 1337 volumes: - ./uploads:/var/www/html/uploads + environment: + - HOSTIP=192.168.X.X # IP of the host machine for the self signed certificate (https is needed for PWA) ``` Go to http://localhost:1337 to upload files. @@ -23,3 +34,12 @@ Go to http://localhost:1337 to upload files. Files will be uploaded to ./uploads Upload limit size: 10000MB + +## Usage as PWA (Progressive Web App) + +After initial start you find the root ca certificate in the uploads folder. Install it on your device to trust the self signed certificates for the local ip defined by the `HOSTIP` environment variable. +After that you can install the webapp as PWA on your device. You may need to reload the page after the certificate is installed. + +A PWA can only be installed via https. So please open the webapp via https://localhost:1337 after installing the ca certificate. + +**Advantage**: You can directly share files from your native share menu on the device to the webapp. diff --git a/compose.yml b/compose.yml index 7ce9916..d8347a2 100644 --- a/compose.yml +++ b/compose.yml @@ -4,8 +4,7 @@ services: # when using directly from the github hub # image: ghcr.io/fabalexsie/simple-web-upload-docker:master ports: - - "1337:80" - - "1338:443" + - "1337:443" volumes: - ./uploads:/var/www/html/uploads # this is just for testing purposes diff --git a/ssl.conf b/ssl.conf index 5dc9e40..fbc325a 100644 --- a/ssl.conf +++ b/ssl.conf @@ -12,8 +12,12 @@ server { ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; - # redirect non http traffic to https - error_page 497 =301 https://$host:1338$request_uri; # 1338 should be the port on the host where the docker container is running + # redirect non https traffic to http port + error_page 497 = @fallback; + + location @fallback { + proxy_pass http://localhost:80; + } # Make site accessible from http://localhost/ server_name _;