An opinionated way of building nginx plus as apigateway. Aimed to reduce & simplify the api onboarding
Shell 28.38%Dockerfile 71.62%
diy-nginx-plus-api-gateway's Introduction
diy-nginx-plus-api-gateway - build a opinionated APIGateway
Pre-requisites
Obtain the NGINX Plus license :
1. If you are planning to run nginx plus as apigateway then copy nginx plus license nginx-repo.crt & nginx-repo.key to /etc/ssl/nginx/
2. If you are planning to run nginx oss as apigateway then you don't need nginx plus license, however you will have to inspect the conf files inside to remove
certain directive which pertains to nginx plus. I have highlighted those directives with comments in the conf files.
Run NGINX Plus docker container
Build an image from your Dockerfile :
# To build the Docker image : Run command from the folder containing the `Dockerfile`
$ docker build -t nginx-plus-api-gateway-simple .# If you made changes to the Dockerfile and need to rebuild you probably need to use--no-cache
$ docker build -t nginx-plus-api-gateway-simple . --no-cache
Start the Nginx Plus container :
# Start a new container and publish container ports 80 (HTTP), 443 (HTTPS), 8000 (Demo instructions) and 8080 (NGINX Plus Dashboard) to the host
$ docker run --name mynginxplus_simple -p 80:80 -p 443:443 -p 8080:8080 -p 8000:8000 -p 9000:9000 -d nginx-plus-api-gateway-simple
Access NGiNX Plus Dashbaord :
# Open your favourite dashboard and enter the below url
$ http://localhost:8080/dashboard.html
Start testing the deployed API :
# [If you're using httpie] Main API traffic flowing through port 80.
$ http :/warehouse-api/inventory
$ http :/warehouse-api/pricing
# [If you're using curl] Main API traffic flowing through port 80.
$ curl http://localhost/warehouse-api/inventory
$ curl http://localhost/warehouse-api/pricing
Start testing the default API comes with NGiNX Plus API Gateway :
# [If you're using httpie] Main API traffic flowing through port 80.
$ http :8080/api/6/nginx
$ http :8080/api/6/http/upstreams
# [If you're using curl] Main API traffic flowing through port 80.
$ curl http://localhost:8080/api/6/nginx
$ curl http://localhost:8080/api/6/http/upstreams
Docker commands to clean the nginx-plus containers and images create abvoe :
# To list nginxplus running container
$ docker ps | grep mynginxplus_simple
# To stop the nginxplus running container
$ docker stop | docker ps | grep mynginxplus_simple
# To remoe the nginxplus iamge
$ docker rmi nginx-plus-api-gateway-simple
Thank you for the clear instructions on the Nginx plus concept. I am installing Nginx plus for the first time. I am trying to build the image but i see this issue. Anything i am missing thats giving me this error?
#9 45.41 Unpacking nginx-plus (23-2stretch) ...
#9 46.26 Setting up nginx-plus (23-2stretch) ...
#9 46.44 invoke-rc.d: could not determine current runlevel
#9 46.45 invoke-rc.d: policy-rc.d denied execution of start.
#9 46.95 + apt-get remove --purge --auto-remove -y gnupg1
#9 46.98 Reading package lists...
#9 48.66 Building dependency tree...
#9 48.97 Reading state information...
#9 49.31 The following packages will be REMOVED:
#9 49.31 gnupg1* libreadline7* readline-common*
#9 49.59 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
#9 49.59 After this operation, 1935 kB disk space will be freed.
(Reading database ... 6950 files and directories currently installed.)
#9 49.63 Removing gnupg1 (1.4.21-4+deb9u1) ...
#9 49.73 Removing libreadline7:amd64 (7.0-3) ...
#9 49.84 Removing readline-common (7.0-3) ...
#9 49.95 Processing triggers for libc-bin (2.24-11+deb9u4) ...
(Reading database ... 6896 files and directories currently installed.)
#9 50.09 Purging configuration files for readline-common (7.0-3) ...
#9 50.28 + apt-get install -y nginx-plus-module-njs
#9 50.31 Reading package lists...
#9 51.70 Building dependency tree...
#9 51.91 Reading state information...
#9 52.01 Some packages could not be installed. This may mean that you have
#9 52.01 requested an impossible situation or if you are using the unstable
#9 52.01 distribution that some required packages have not yet been created
#9 52.01 or been moved out of Incoming.
#9 52.01 The following information may help to resolve the situation:
#9 52.01
#9 52.01 The following packages have unmet dependencies:
#9 52.17 nginx-plus-module-njs : Depends: nginx-plus-r24 but it is not installable
#9 52.25 E: Unable to correct problems, you have held broken packages.