Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjy8001/nginx-proxy
Easy configurable reverse proxy
https://github.com/benjy8001/nginx-proxy
docker https nginx proxy
Last synced: 6 days ago
JSON representation
Easy configurable reverse proxy
- Host: GitHub
- URL: https://github.com/benjy8001/nginx-proxy
- Owner: benjy8001
- Created: 2022-03-30T10:01:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-07-26T09:46:20.000Z (over 2 years ago)
- Last Synced: 2023-03-06T03:55:33.556Z (over 1 year ago)
- Topics: docker, https, nginx, proxy
- Language: Shell
- Homepage:
- Size: 87.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
little project to help your project to use nginx-proxy.
![](docs/schema.png)
nginx-proxy sets up a container running nginx and docker-gen. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped.
See [jwilder/nginx-proxy repository](https://github.com/jwilder/nginx-proxy) for more informations.
# Install
Clone this repository in parent directory's of your project
```shell script
$ mkdir -p [PROJECTS_DIRECTORY_PATH]/nginx-proxy && cd $_
$ wget -q https://github.com/benjy8001/raw/master/bin/installer -O -|bash
```# HOW TO USE
### MANUAL CONFIGURATIONAdd to your ~/.bashrc or ~/.zshrc
```bash
export NGINX_PROXY=enabled
export NGINX_PROXY_DIRECTORY=[PROJECTS_DIRECTORY_PATH]/nginx-proxy
PATH=$PATH:$NGINX_PROXY_DIRECTORY/bin
```### ACTIVATE OR NOT
define an environment variable to "enabled" or "disabled" usage of nginx-proxy.```bash
$ export NGINX_PROXY=enabled
$ export NGINX_PROXY=disabled
```or edit .env file
```dotenv
[...]
NGINX_PROXY=enabled
[...]
```### UPDATE YOUR MAKEFILE
add lines in your Makefile and call label:
```makefile
require-nginx:
ifndef NGINX_PROXY_DIRECTORY
printf " \033[31m You should install nginx proxy ... \033[0m\n"
printf " \n"
printf " \033[31m cd ~/Projects && mkdir nginx-proxy && cd nginx-proxy \033[0m\n"
printf " \033[31m wget -q https://github.com/benjy8001/nginx-proxy/raw/master/bin/installer -O -|bash \033[0m\n"
printf " \n"
exit 1
endifstart_nginx_proxy:
ifeq (${NGINX_PROXY}, enabled)
make require-nginx
nginx_proxy
endifstart: start_nginx_proxy
```Example :
```makefile
include .env
exportrequire-nginx:
ifndef NGINX_PROXY_DIRECTORY
printf " \033[31m You should install nginx proxy ... \033[0m\n"
printf " \n"
printf " \033[31m cd ~/Projects && mkdir nginx-proxy && cd nginx-proxy \033[0m\n"
printf " \033[31m wget -q https://github.com/benjy8001/raw/master/bin/installer -O -|bash \033[0m\n"
printf " \n"
exit 1
endifstart_nginx_proxy:
ifeq (${NGINX_PROXY}, enabled)
make require-nginx
nginx_proxy
endifregistry_login: ## login on registry
registry_login:
docker login babel.ngc-data.fr:8443start-docker: ## Start the dockers
start-docker: registry_login start_nginx_proxy
@docker-compose up -dstart: ## alias of start-docker
start: start-docker.DEFAULT_GOAL := help
help:
@grep -E '(^[a-zA-Z_-]+:.*?## .*$$)|(^## )' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' | sed 's/Makefile.\(\s\)*//'
.PHONY: help```
### UDPATE YOUR DOCKER-COMPOSE or DOCKER COMMAND
Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com`
```shell script
$ docker run -e VIRTUAL_HOST=foo.bar.com ...
```
The containers being proxied must expose the port to be proxied, either by using the EXPOSE directive in their Dockerfile or by using the `--expose` flag to docker run or docker create.Provided your DNS is setup to forward foo.bar.com to the host running nginx-proxy, the request will be routed to a container with the `VIRTUAL_HOST` env var set.
You can also define env vars in your `docker-compose.yml`
```yaml
version: "3.3"
services:
api_httpd:
image: nginx
environment:
VIRTUAL_HOST: subdomain.youdomain.com
VIRTUAL_PORT: 80
```### USE SSL
#### Setup
To use ssl (https) you need to generate a local authority root certificate using this command :
```bash
nginx_proxy_ssl gen_authority
```
(you will need to generate a new certificate after expiration (2 years))Then, make your web browser trust the root certificate (`docker/certs/AUTHORITY.crt`) as an authority (https://windowsreport.com/install-windows-10-root-certificates/).
#### Usage
You can add task to you Makefile
```Makefile
add-certificates: require-nginx
ifeq ("$(wildcard ${NGINX_PROXY_DIRECTORY}/docker/certs/my.domain.test.crt)","")
echo "generating nginx proxy certs"
nginx_proxy_ssl gen my.domain.test
nginx_proxy restart
else
echo "certs aldready added"
endifstart_nginx_proxy: add-certificates
nginx_proxy
```