Giter Club home page Giter Club logo

localreverseproxy's Introduction

Local Reverse Proxy

The reverse proxy server for the local environment can help to run several docker projects locally via the 80 port.

Each time when you face issues when you need to run several docker projects and you don't want to stop and run it again and again, or you just need your projects to work on 80 port. Use this Local Reverse Proxy!

Article: How to run multiple Docker projects under port 80 using an off-the-shelf local Reverse Proxy.

How it works (diagram)

    Client                  Host (OS mapping)          Reverse Proxy        Target Server (Docker App)
   +------+    request      +-----------------+       +--------------+         +----------------+
   │      │ 'example.local' │                 │       │              │  proxy  │                │
   │      │────────────────►│ 'example.local' │──────►│              │────────►│                │
   │      │    response     │    mapped to    │       │ 127.0.0.1:80 │         │ localhost:8080 │
   │      │◄────────────────│   '127.0.0.1'   │◄──────│              │◄────────│                │
   │      │                 │                 │       │              │         │                │
   +------+                 +-----------------+       +--------------+         +----------------+
   (Browser)                    /etc/hosts

How to set up Local Reverse Proxy

How run Local Reverse Proxy

  1. Download and Install Go

    • For macOS/Linux just follow instruction.
    • For windows - install Go into Windows OS, and use CMD to build and run Go app.
  2. Clone and go into cloned repository.

  3. Let's compile Go app

    go mod tidy
    go build
  4. Run Local Reverse Proxy:

    ./localreverseproxy
    
    # or if you have permissions errors use with sudo
    sudo ./localreverseproxy 
  5. If everything ok you will see in a console:

    Reverse proxy is started.
  6. Now visit http://localhost, you should see in the browser

    Server proxy started successfully!

    and in the console you should see

    Requested `localhost` host with method `GET` and URI `/`
    Requested `localhost` host with method `GET` and URI `/favicon.ico`

    [!NOTE] Each http request will be logged and you will see it in the console, so you can check how things going.

How to configure docker projects to work with Local Reverse Proxy

  1. Configure ports for your docker projects:

    • Create docker-compose.override.yml in your projects.
    • Add there apache or nginx service and change a port. Because by default most of projects uses 80 or 443 ports.
      Yaml should look like this:
    services:   
      nginx:
        ports: !override # helps to reset ports.
          - "8080:80" # Now set up new external port `8080`

    [!NOTE] !override works only on the version v2.24.5 and above of docker-compose.

    For another project you can set 8090 port.

    • Recreate docker containers inside your project directory to containers use new port.
    docker-compose up -d --force-recreate
    • Do the same steps for another docker project but use another port, as example 8090.

    [!NOTE] Remember one port for one service/container/device!

    [!NOTE] Your 2 and more projects have to run and work without any issues, if not check that external ports be unique.

  2. Go to the directory of cloned localreverseproxy repository again.

  3. Add your docker projects domains into services.json file. Where:

    • Key is local domain address.
    • Value is URL:Port of docker service. Use http://localhost:<your_service_port>

Note

You can use simple regexp in Key fields of services.json file.
To have a mask, like: *.local.

Note

If you change the services.json file you don't need to compile app again. It is read in runtime.

Note

Don't forget add domains into your hosts file.


Roadmap

  • Configure routing via json.
  • Implement reverse-proxy functionality.
  • Add documentation how to use it.
  • Show error if port is busy.
  • Add requests logging in console.
  • Add service response logging in console.
  • Add supporting https
  • Add supporting url paths

localreverseproxy's People

Contributors

renakdup avatar

Watchers

 avatar

localreverseproxy's Issues

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.