Code Monkey home page Code Monkey logo

nginx-for-subdomains's Introduction

nginx-for-subdomains

Assume you want to run several web applications/service on the same server. Each of the applications runs in a separate container and you want to have a redirection for every application by subdomain.

  • myfirstapp.mydomain.com will access myfirstapp
  • myotherapp.mydomain.com will access myotherapp

This is aimple set up using nginx to automatically root to the app to the right container based on subdomains of the url linked to container names.

It also takes care of making sure the access is only https if you want.

Usage

Update configxxx/subdomains.conf server part with your domain name.

Update configxxx/subdomains.conf with the port mapping of your services.

If your are running in ssl configuration, create a key directory where you put your certificate in it and check the key location directif in config/include/ssl.conf

Create a network for the containers accessible for nginx

docker network create nginx-net

Start nginx with right links, dependant on what config you choose.

  • For configuration with ssl :
docker run -d --name nginx-main --network nginx-net -v $(pwd)/config:/etc/nginx/conf.d:ro -v $(pwd)/pages:/usr/share/nginx/html:ro  -v $(pwd)/keys:/etc/nginx/keys:ro -p 80:80 -p 443:443 nginx
  • For configuration without ssl :
docker run -d --name nginx-main --network nginx-net -v $(pwd)/config-nossl:/etc/nginx/conf.d:ro -v $(pwd)/pages:/usr/share/nginx/html:ro -p 80:80 nginx

Start a service

  • start the container
  • connect the container in the nginx network with the alias right service name.

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.