Serve your static files using nginx. The static files can be either pulled from git repository or mounted via docker volume to /home/server/storage.
If configured via git repository, this will automatically sync it to the repository via a cron
job for every 5 minutes. If using git repository, the files will be clone into /home/server/storage.
Nginx will serve its contents using root folder /home/server/storage/public. So, make sure your
repository contains a public folder inside. This is to make sure the .git folder won't be served
by nginx.
You can also upload files via sftp by configuring an sftp password using environment variable SFTP_PASSWORD.
| Docker Tag | Git Release | Nginx Version | Alpine Version | Base Image |
|---|---|---|---|---|
| latest/1.0.0 | Master Branch | 1.19.1 | 3.12 | flashspys/nginx-static |
$ docker pull smujaddid/nginx-server-static
$ docker run -it --rm \
-e 'SFTP_PASSWORD=test' \
-e '[email protected]:username/repo-name.git' \
-e 'STORAGE_GIT_NAME=Kimi no Nawa' \
-e '[email protected]' \
-e 'STORAGE_GIT_USERNAME=username' \
-e 'STORAGE_GIT_PERSONAL_TOKEN=access_token' \
-e 'STORAGE_GIT_BRANCH=master' \
-v /path/to/storage:/home/server/storage \
-p 2222:22
-p 8000:80
-d --name static-server \
smujaddid/nginx-server-static
version: "3.7"
services:
static-server:
image: smujaddid/nginx-server-static:latest
container_name: static-server
environment:
- SFTP_PASSWORD=test
- [email protected]:username/repo-name.git
- STORAGE_GIT_NAME=Kimi no Nawa
- [email protected]
- STORAGE_GIT_USERNAME=username
- STORAGE_GIT_PERSONAL_TOKEN=access_token
- STORAGE_GIT_BRANCH=master
ports:
- "2222:22"
- "8000:80"
You can connect this to your laravel application via sftp configured file storage. You can read the documentation here.
The following is an example of a storage disk configuration in config/filesystem.php:
'disks' => [
'uploads' => [
'driver' => 'sftp',
'host' => env('STATIC_SERVER_HOST', 'static-server'),
'port' => env('STATIC_SERVER_PORT', 22),
'username' => env('STATIC_SERVER_USERNAME', 'sftp'),
'password' => env('STATIC_SERVER_PASSWORD', 'test'),
'root' => env('STATIC_SERVER_ROOT', 'storage/public'),
'timeout' => env('STATIC_SERVER_TIMEOUT', 10),
'directory_perm' => 0755,
'url_prefix' => env('STATIC_SERVER_URL_PREFIX', 'http://localhost:8000'),
],
],
Note: Make sure your storage folder have the public folder inside
If your default disk is not uploads then make sure to call the disk method first.
Storage::disk('uploads')->put('avatars/1', $fileContents);
MIT
Copyright (c) 2020 Sibghatullah Mujaddid
Content type
Image
Digest
Size
35.6 MB
Last updated
about 5 years ago
docker pull smujaddid/nginx-server-static