Skip to content

Commit 92b1cb4

Browse files
author
Fumarola Fabio (UniCredit)
committed
initial commit
0 parents  commit 92b1cb4

11 files changed

+495
-0
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:1.9.9
2+
3+
# add need configurations

README.md

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# NGINX with Proxy Generator
2+
3+
It allows us to start :
4+
5+
1. a Nginx instance
6+
2. generate proxy configurations
7+
3. generate basic auth
8+
9+
The application can be managed via:
10+
1. `manage.sh`
11+
2. or manually as explained below
12+
13+
14+
## Manage via `manage.sh`
15+
16+
```bash
17+
usage manage.sh [clean_conf | gen_default | gen_all | start | restart | reload | stop]
18+
```
19+
options:
20+
21+
1. clean_conf: remove all the configuration from `nginx/conf.d/`
22+
2. gen_default: generate only the `default.conf` file
23+
3. gen_all: generate all the configurations files from the `nginx_conf.json` file
24+
4. start: start the docker container of nginx
25+
5. restart: restart the docker container
26+
6. reload: reload the configuration in `nginx/conf.d/`
27+
7. stop: stop the container and clean the current folder
28+
29+
## Manual Configurations
30+
31+
### Reload NGINX confs
32+
33+
```bash
34+
docker exec -it <container_name> /usr/sbin/nginx -t
35+
```
36+
37+
### Start NGINX
38+
39+
```bash
40+
docker-compose up -d
41+
```
42+
43+
### Generate Proxy configurations
44+
45+
The python script `nginxify.py` can be used to generate `*.conf` files.
46+
47+
```bash
48+
49+
./nginxify.py --help
50+
51+
usage: nginxify.py [-h] [--default ONLY_DEFAULT] [--dest DEST_FOLDER]
52+
[--conf CONFS_FILE] [--overwrite OVERWRITE]
53+
54+
nginx conf generator
55+
56+
optional arguments:
57+
-h, --help show this help message and exit
58+
--default ONLY_DEFAULT
59+
if true generate only the default configurations
60+
--dest DEST_FOLDER The folder to save the *.conf files. Default value
61+
'./nginx/conf.d/'
62+
--conf CONFS_FILE The json file with the configurations. Default value
63+
'nginx_conf.json'
64+
--overwrite OVERWRITE
65+
True to overwrite all the configurations files
66+
```
67+
68+
#### Json File Structure
69+
The file contains a list of `proxies` with:
70+
- **name**: the name of the proxy
71+
- **server_names**: the name of the domain name to expose the service
72+
- **docker_name**: the name or ip address of the docker container to expose
73+
- **docker_port**: the internal port of the container
74+
- **secured**: if the service should be secured with [nginx auth_basic]()
75+
76+
```json
77+
78+
{
79+
"proxies": [
80+
{
81+
"name": "spark",
82+
"servers": [
83+
"spark.datatoknowledge.it"
84+
],
85+
"dockers": [
86+
"spark-master-0:8080"
87+
],
88+
"secured": true
89+
},
90+
{
91+
"name": "es",
92+
"servers": [
93+
"es.datatoknowledge.it"
94+
],
95+
"dockers": [
96+
"es-data-0:9200",
97+
"es-data-1:9200",
98+
"es-data-1:9200"
99+
],
100+
"docker_name": "es-data-0",
101+
"docker_port": "9200",
102+
"secured": true
103+
},
104+
{
105+
"name": "datatoknowledge",
106+
"servers": [
107+
"datatoknowledge.it",
108+
"www.datatoknowledge.it"
109+
],
110+
"dockers": [
111+
"dtk-0:5000"
112+
],
113+
"secured": false
114+
}
115+
]
116+
}
117+
118+
```
119+
120+
### Password generator
121+
122+
The script `password_generator.py` can be used to generate a file that stores the access passwords. By default it stores all the password in `/nginx/htpasswd/secure`. This file is mapped to the running docker container.
123+
124+
#### Usage
125+
126+
```bash
127+
./password_generator.py --help
128+
usage: password_generator.py [-h] [--file DEST_FOLDER] [--user USER]
129+
[--pwd PWD]
130+
131+
nginx auth file generator
132+
133+
optional arguments:
134+
-h, --help show this help message and exit
135+
--file DEST_FOLDER the folder to save the new username:password pair
136+
--user USER the username for the new user
137+
--pwd PWD the password for the new user
138+
```
139+
140+
### Index 404 and 50x pages
141+
142+
As default there is a custom_404 custom_50x and index page in the folder `./nginx/www/html`. If you need you can change these pages.

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
nginx:
2+
build: .
3+
ports:
4+
- "80:80"
5+
- "443:443"
6+
volumes:
7+
- ./nginx/conf.d:/etc/nginx/conf.d
8+
- ./nginx/sites-enabled:/etc/nginx/sites-enabled
9+
- ./nginx/htpasswd:/etc/nginx/htpasswd
10+
- ./nginx/www/html:/usr/share/nginx/html

manage.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
case $1 in
4+
clean_conf)
5+
rm -f ./nginx/conf.d/*
6+
;;
7+
gen_default)
8+
./nginxify.py --default True
9+
;;
10+
gen_all)
11+
./nginxify.py --overwrite True
12+
;;
13+
start)
14+
./nginxify.py --default True
15+
docker-compose up -d
16+
;;
17+
restart)
18+
./nginxify.py --default True
19+
docker-compose restart
20+
;;
21+
reload)
22+
name=`docker-compose ps -q`
23+
docker exec -it ${name} /usr/sbin/nginx -t
24+
;;
25+
stop)
26+
docker-compose stop
27+
docker-compose rm -f
28+
;;
29+
*)
30+
echo 'usage manage.sh [clean_conf | gen_default | gen_all | start | restart | reload | stop]'
31+
esac

nginx/conf.d/default.conf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server {
2+
listen 80 default_server;
3+
listen [::]:80 default_server ipv6only=on;
4+
5+
6+
error_page 404 /custom_404.html;
7+
location = /custom_404.html {
8+
root /usr/share/nginx/html;
9+
internal;
10+
}
11+
12+
error_page 500 502 503 504 /custom_50x.html;
13+
location = /custom_50x.html {
14+
root /usr/share/nginx/html;
15+
internal;
16+
}
17+
}
18+

nginx/www/html/custom_404.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>404</title>
4+
</head>
5+
<body bgcolor=cccccc>
6+
7+
<table border=0 width=100% height=100%><tr><td height=100% width=100% align=center>
8+
9+
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="500" height="300" id="err" align="middle">
10+
<param name="allowScriptAccess" value="sameDomain" />
11+
<param name="movie" value="http://www.tinsanity.net/err.swf?err=404&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" />
12+
<param name="quality" value="high" />
13+
<param name="bgcolor" value="#cccccc" />
14+
<embed src="http://www.tinsanity.net/err.swf?err=404&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" quality="high" bgcolor="#cccccc" width="500" height="300" name="err" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
15+
</object>
16+
17+
</td></tr></table>
18+
</body>
19+
</html>

nginx/www/html/custom_50x.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>404</title>
4+
</head>
5+
<body bgcolor=cccccc>
6+
7+
<table border=0 width=100% height=100%><tr><td height=100% width=100% align=center>
8+
9+
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="500" height="300" id="err" align="middle">
10+
<param name="allowScriptAccess" value="sameDomain" />
11+
<param name="movie" value="http://www.tinsanity.net/err.swf?err=404&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" />
12+
<param name="quality" value="high" />
13+
<param name="bgcolor" value="#cccccc" />
14+
<embed src="http://www.tinsanity.net/err.swf?err=503&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" quality="high" bgcolor="#cccccc" width="500" height="300" name="err" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
15+
</object>
16+
17+
</td></tr></table>
18+
</body>
19+
</html>

nginx/www/html/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>404</title>
4+
</head>
5+
<body bgcolor=cccccc>
6+
7+
<table border=0 width=100% height=100%><tr><td height=100% width=100% align=center>
8+
9+
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="500" height="300" id="err" align="middle">
10+
<param name="allowScriptAccess" value="sameDomain" />
11+
<param name="movie" value="http://www.tinsanity.net/err.swf?err=404&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" />
12+
<param name="quality" value="high" />
13+
<param name="bgcolor" value="#cccccc" />
14+
<embed src="http://www.tinsanity.net/err.swf?err=NO_PAGE&subtext=THE PAGE YOU ARE LOOKING FOR DOES NOT EXIST. SORRY :'(" quality="high" bgcolor="#cccccc" width="500" height="300" name="err" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
15+
</object>
16+
17+
</td></tr></table>
18+
</body>
19+
</html>

nginx_conf.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"proxies": [
3+
{
4+
"name": "spark",
5+
"servers": [
6+
"spark.datatoknowledge.it"
7+
],
8+
"dockers": [
9+
"spark-master-0:8080"
10+
],
11+
"secured": true
12+
},
13+
{
14+
"name": "es",
15+
"servers": [
16+
"es.datatoknowledge.it"
17+
],
18+
"dockers": [
19+
"es-data-0:9200",
20+
"es-data-1:9200",
21+
"es-data-1:9200"
22+
],
23+
"docker_name": "es-data-0",
24+
"docker_port": "9200",
25+
"secured": true
26+
},
27+
{
28+
"name": "datatoknowledge",
29+
"servers": [
30+
"datatoknowledge.it",
31+
"www.datatoknowledge.it"
32+
],
33+
"dockers": [
34+
"dtk-0:5000"
35+
],
36+
"secured": false
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)