GithubHelp home page GithubHelp logo

b-rajesh / diy-nginx-plus-api-gateway Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 6.0 184 KB

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

What's in the folder structure

alt text

Policies folder structure

alt text

diy-nginx-plus-api-gateway's People

Contributors

b-rajesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

diy-nginx-plus-api-gateway's Issues

Error while building the image

Hi Rajesh,

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-2
stretch) ...
#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.

executor failed running [/bin/sh -c set -x && apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends --no-install-suggests -y apt-transport-https ca-certificates gnupg1 && NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; found=''; for server in ha.pool.sks-keyservers.net hkp://keyserver.ubuntu.com:80 hkp://p80.pool.sks-keyservers.net:80 pgp.mit.edu ; do echo "Fetching GPG key $NGINX_GPGKEY from $server"; apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; done; test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; echo "Acquire::https::plus-pkgs.nginx.com::Verify-Peer "true";" >> /etc/apt/apt.conf.d/90nginx && echo "Acquire::https::plus-pkgs.nginx.com::Verify-Host "true";" >> /etc/apt/apt.conf.d/90nginx && echo "Acquire::https::plus-pkgs.nginx.com::SslCert "/etc/ssl/nginx/nginx-repo.crt";" >> /etc/apt/apt.conf.d/90nginx && echo "Acquire::https::plus-pkgs.nginx.com::SslKey "/etc/ssl/nginx/nginx-repo.key";" >> /etc/apt/apt.conf.d/90nginx && printf "deb https://plus-pkgs.nginx.com/debian stretch nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list && apt-get update && apt-get install -y nginx-plus && apt-get remove --purge --auto-remove -y gnupg1 && apt-get install -y nginx-plus-module-njs && apt-get install -y nginx-plus-module-opentracing && apt-get install nginx-plus-module-headers-more && rm /etc/nginx/conf.d/default.conf && apt-get install -y jq && rm -rf /var/lib/apt/lists/* && rm -rf /etc/ssl/nginx]: exit code: 100

I really appreciate any help on this.

Thanks!
~Swetha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.