|
| 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. |
0 commit comments