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.
git clone https://github.com/leesei/docker-nginx-cors
./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.
- Place an certificate key pair in
conf.d/
(with namehttps.{key,crt}
) - Enable
https.conf
include inconf.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
- 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 inconf.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.
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