Skip to content

Commit

Permalink
run http and https on the same port
Browse files Browse the repository at this point in the history
  • Loading branch information
fabalexsie committed May 31, 2024
1 parent c4f66f0 commit 30f64a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -13,13 +22,24 @@ 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.
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.
3 changes: 1 addition & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions ssl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down

0 comments on commit 30f64a8

Please sign in to comment.