GithubHelp home page GithubHelp logo

miguelramosfdz / nginx-autoproxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hach-que-docker/nginx-autoproxy

0.0 3.0 0.0 184 KB

A Docker image for forwarding HTTP and HTTPS requests from a host machine to one or more Docker containers

Home Page: https://index.docker.io/u/hachque/nginx-autoproxy/

nginx-autoproxy's Introduction

Usage

This image is an automated reverse proxy using Nginx. It is designed to reverse proxy multiple other Docker containers and thus route requests from the host's HTTP and HTTPS ports to different containers based on the hostname.

This image requires a reasonable amount of preconfiguration, in that you need to specify how the Nginx configuration will be generated for each of the servers.

To configure this image, create a config directory, with a servers directory inside it and a generate script inside that. It should be mapped in such a way that in the container, /config/servers/generate exists and is executable.

WARNING: Do not reverse proxy to SSL ports. There are known issues with downloading files and reverse proxying to an SSL port, so you should just use port 80 instead. In this scenario, the reverse proxy still offers SSL to the end-user, but uses plain HTTP while routing to the other Docker instances.

Here is an example script that you can change for your own needs:

#!/bin/bash

cat >example.com.conf <<EOF
server {
    server_name example.com;

    listen      *:80;
    return 301 https://\$host\$request_uri;
}

server {
    server_name example.com;

    listen      *:443 ssl;

    ssl_certificate      /etc/nginx/certs/cert-example.com.pem;
    ssl_certificate_key  /etc/nginx/certs/cert-example.com.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        # Note that this is HTTP on port 80 and NOT SSL!
        proxy_pass http://${LINKED_EXAMPLE_COM_PORT_80_TCP_ADDR}:${LINKED_EXAMPLE_COM_PORT_80_TCP_PORT};
        include reverse.inc;
    }
}

EOF

cat >another.com.conf <<EOF
server {
    server_name another.com;

    listen      *:80;

    location / {
        try_files \$uri \$uri/ /index.php;
        if ( !-f \$request_filename )
        {
            rewrite ^/(.*)$ /index.php?__path__=/tychaia/\$1&__pageview=TychaiaStandardPageView&__appname=Unearth last;
            break;
        }
    }

    location /index.php {
        proxy_pass http://${LINKED_ANOTHER_COM_PORT_80_TCP_ADDR}:${LINKED_ANOTHER_COM_PORT_80_TCP_PORT};
        include reverse.inc;
    }
}

EOF

The other critical step is linking the containers together correctly. The example above assumes that this container has been run with the following command:

/usr/bin/docker run -p 80:80 -p 443:443 -v /path/to/autoproxy/config:/config --name=autoproxy --link example.com:linked_example_com --link another.com:linked_another_com hachque/nginx-autoproxy

What do these parameters do?

-p 80:80 = forward the host's HTTP port to this proxy
-p 443:443 = forward the host's HTTPS port to this proxy
-v /path/to/autoproxy/config:/config = map the configuration directory for the proxy
--name autoproxy = the name of the container
--link example.com:linked_example_com = link the example.com container to this one
--link another.com:linked_another_com = link the another.com container to this one
hachque/nginx-autoproxy = the name of the image

Note that the names linked_example_com and linked_another_com directly correspond to the variables names used in the generate script.

This image is intended to be used in such a way that a new container is created each time it is started, instead of starting and stopping a pre-existing container from this image. You should configure your service startup so that the container is stopped and removed each time. A systemd configuration file may look like:

[Unit]
Description=Nginx proxy for main sites
Requires=docker.service example.com.service another.com.service

[Service]
ExecStart=<command to start instance, see above>
ExecStop=/usr/bin/docker stop autoproxy
ExecStop=/usr/bin/docker rm autoproxy
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

SSL configuration

All files located in the /config/certs directory (if present) are copied to /etc/nginx/certs. This allows you to reference SSL certificates from within the Nginx server configuration.

SSH / Login

Username: root

Password: linux

nginx-autoproxy's People

Contributors

hach-que avatar

Watchers

 avatar  avatar  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.