leesei / docker-nginx-cors

Serve a folder with Docker's `nginx:alpine`, with CORS, HTTPS and .htaccess configs available.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker-nginx-cors

A script for starting Docker's nginx:alpine image with CORS, and optionally HTTPS, on arbitrary folder and arbitrary port.

This is a script that load config files in the current directory rather than a Docker image. This allows for multiple instances of docker-nginx-cors running simultaneously with different configs.

Install

git clone https://github.com/leesei/docker-nginx-cors

Usage

./nserve -p 9000 ~/share

Use this command to verify the config of the created container:

docker inspect --format="{{.Volumes}}" [${CONTAINER_NAME}|${CONTAINER_ID}]
docker inspect --format="{{.Config.Labels}}" [${CONTAINER_NAME}|${CONTAINER_ID}]

# with [`jq`](https://stedolan.github.io/jq/manual/)
docker inspect [${CONTAINER_NAME}|${CONTAINER_ID}] | jq .[0].Volumes
docker inspect [${CONTAINER_NAME}|${CONTAINER_ID}] | jq .[0].Config.Labels

You can also fork this repo and customize nginx.conf, nginx.vh.default.conf to fit your needs.

HTTPS

  • Place an certificate key pair in conf.d/ (with name https.{key,crt})
  • Enable https.conf include in conf.d/default.conf

To create self-signed certs:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx/conf.d/https.key -out nginx/conf.d/https.crt
# fill the IP/domain of your server to "Common Name"
# otherwise the browser will reject to connect to the server

Access Control

  • Create conf.d/.htaccess to specify the username and password
    Or use Perl script, invoke multiple times for multiple users.
echo "<username>:`perl -le 'print crypt(\"<password>\", "salt-hash")'`:comment" >> nginx/conf.d/.htaccess
  • Enable auth-basic.conf include in conf.d/default.conf
  • You can also create new location block that includes auth-basic.conf

Its recommended to enable HTTPS with Basic Auth, otherwise the credentials will be sent in plaintext and vulnerable to sniffing.

References

h5bp/server-configs-nginx: Nginx HTTP server boilerplate configs
Cipherli.st - Strong Ciphers for Apache, nginx and Lighttpd
How To Set Up Nginx with HTTP/2 Support on Ubuntu 16.04 | DigitalOcean
HTTP 2.0 With Nginx - Servers for Hackers NGINX Docs | Restricting Access with HTTP Basic Authentication

About

Serve a folder with Docker's `nginx:alpine`, with CORS, HTTPS and .htaccess configs available.

License:MIT License


Languages

Language:Shell 100.0%