Giter Club home page Giter Club logo

apigateway-reverse-proxy's Introduction

apigateway-reverse-proxy

This is a docker-based reverse proxy solution running between AWS API Gateway and backend server with capabilities of API Gateway client certification verification and SSL/TLS termination.

Perquisites

  1. a FQDN for your proxy service, e.g. proxy.pahud.net

  2. site certificate, full certificate chain and private key of the proxy FQDN (self-signed cert will prevent API Gateway from SSL handshaking so make sure the cert is signed by trusted CA)

  3. client certificate generated by AWS API Gateway(HOWTO)

  4. install docker daemon on the proxy server

Setup

  1. checkout the repository into the proxy server

  2. $ cd apigateway-reverse-proxy

  3. save your full certificate chain, privaet key and client certificate into apigateway-reverse-proxy

  4. edit build.sh, configure PRIVATE_KEY CERT and CLIENT_CERT variables to the local path of the private key, full certificate chain and client certificate respectively.

  5. build the docker image by $ bash build.sh

  6. on built success, you will have apigw-reverse-proxy as the docker image

    # docker images apigw-reverse-proxy
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    apigw-reverse-proxy   latest              34116d8ad2f9        15 minutes ago      433.2 MB
    
  7. edit run.sh , configure SERVER_NAME and BACKEND_SERVER_NAME for your environment

    SERVER_NAME='proxy.pahud.net'
    BACKEND_SERVER_NAME='debug.pahud.net'
    
    • SERVER_NAME is the FQDN of the proxy server
    • BACKEND_SERVER_NAME is the FQDN of proxied service behind the proxy

The architecture will look like this:

API client—>AWS API Gateway —> SERVER_NAME(i.e. the proxy) —> BACKEND_SERVER_NAME(i.e. the backend server)

  1. start the proxy service by bash run.sh

Test

  1. create a API resource/method in AWS API Gateway console with HTTP Proxy integratin
  2. configure the SERVER_NAME in the Endpoint URL e.g. https://proxy.pahud.net
  3. make sure select correct client certificate in the Stage Editor
  4. deploy the stage
  5. send a request to API Gateway and see if it returns correctly

Nginx.conf

please note the default nginx.conf.skeleton configuration is having a prefix and rewrite rule of /v1

  location ~ "^/v1/(.+)" {
        rewrite /v1/(.*) /$1  break;
        proxy_ssl_server_name   on;
        proxy_ssl_protocols     TLSv1 TLSv1.1 TLSv1.2;
        proxy_set_header        Host '%BACKEND_SERVER_NAME%';
        proxy_pass              https://%BACKEND_SERVER_NAME%;
    }

In this case, https://SERVER_NAME/v1/{location} will be rewritten and proxy_pass tohttps://BACKEND_SERVER_NAME/{localtion}

If you need full site proxy without URL rewrite, update the nginx.conf.skeleton from:

  	location ~ "^/v1/(.+)" {
        rewrite /v1/(.*) /$1  break;
        proxy_ssl_server_name   on;
        proxy_ssl_protocols     TLSv1 TLSv1.1 TLSv1.2;
        proxy_set_header        Host '%BACKEND_SERVER_NAME%';
        proxy_pass              https://%BACKEND_SERVER_NAME%;
    }

    # toggle off the comments for whole site proxy
    #location / {
    #    proxy_ssl_server_name   on;
    #    proxy_ssl_protocols     TLSv1 TLSv1.1 TLSv1.2;
    #    proxy_set_header        Host '%BACKEND_SERVER_NAME%';
    #    proxy_pass              https://%BACKEND_SERVER_NAME%;
    #}

to

  	#location ~ "^/v1/(.+)" {
    #    rewrite /v1/(.*) /$1  break;
    #    proxy_ssl_server_name   on;
    #    proxy_ssl_protocols     TLSv1 TLSv1.1 TLSv1.2;
    #    proxy_set_header        Host '%BACKEND_SERVER_NAME%';
    #    proxy_pass              https://%BACKEND_SERVER_NAME%;
    #}

    # toggle off the comments for whole site proxy
    location / {
        proxy_ssl_server_name   on;
        proxy_ssl_protocols     TLSv1 TLSv1.1 TLSv1.2;
        proxy_set_header        Host '%BACKEND_SERVER_NAME%';
        proxy_pass              https://%BACKEND_SERVER_NAME%;
    }

apigateway-reverse-proxy's People

Watchers

James Cloos avatar Evgeniy Moskalenko avatar

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.