supinf/proxy-container

By supinf

Updated almost 7 years ago

Proxy using nginx installed on windowsservercore

Image
0

9.3K

supinf/proxy-container repository overview

proxy-container

It is a proxy using nginx that runs on Windows for ECS.
You need to pass PROXY_HOSTIP, PROXY_PORT and PROXY_PREFIX as variables.
Docker-entrypoint.ps1 reads the arguments and writes the values ​​to edit-nginx.conf.

Dockerfile

FROM mcr.microsoft.com/windows/servercore/insider:10.0.17763.107


RUN powershell -Command \
	$ErrorActionPreference = 'Stop'; \
	Invoke-WebRequest -Method Get -Uri http://nginx.org/download/nginx-1.15.12.zip -OutFile c:\nginx-1.15.12.zip ; \
	Expand-Archive -Path c:\nginx-1.15.12.zip -DestinationPath c:\ ; \
	Remove-Item c:\nginx-1.15.12.zip -Force

WORKDIR /nginx-1.15.12

RUN mkdir shell
COPY edit-nginx.conf ./shell
COPY docker-entrypoint.ps1 ./shell

ENTRYPOINT [ "powershell.exe", "./shell/docker-entrypoint.ps1" ]

edit-nginx.conf

#delete


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream backendhostname {
            server PROXY_HOSTIP:PROXY_PORT;
    }

    server {
        listen       9000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /health {
            return 200;
        }

        location / {
            return 404;
        }
        location ~ "^/PROXY_PREFIX/(.*)$" {
        #location ~ "^/ws/[a-zA-Z0-9]*/(.*)$" {
            proxy_pass http://backendhostname/$1;
            proxy_http_version 1.1; #use websocket
            proxy_set_header Upgrade $http_upgrade; #use websocket
            proxy_set_header Connection "upgrade"; #use websocket
        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        #    root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

docker-entrypoint.ps1

# Get local ip adder by metadata
# Include in container(ECS)

$PROXY_HOSTIP=$env:PROXY_HOSTIP
$PROXY_PORT=$env:PROXY_PORT
$PROXY_PREFIX=$env:PROXY_PREFIX

#Get-Content C:\nginx-1.15.9\shell\edit-nginx.conf | % { $_ -replace "EDITNOW","$ipaddr"} > C:\nginx-1.15.9\shell\nginx.conf
$conf1=Get-Content C:\nginx-1.15.12\shell\edit-nginx.conf `
    | % { $_ -replace "PROXY_HOSTIP","$PROXY_HOSTIP"} `
    | % { $_ -replace "PROXY_PORT","$PROXY_PORT"} `
    | % { $_ -replace "PROXY_PREFIX","$PROXY_PREFIX"} `

$conf1 | Out-File  -Encoding Default  C:\nginx-1.15.12\shell\nginx.conf

Move-Item C:\nginx-1.15.12\conf\nginx.conf C:\nginx-1.15.12
Move-Item C:\nginx-1.15.12\shell\nginx.conf C:\nginx-1.15.12\conf\nginx.conf

CMD /C /nginx-1.15.12/nginx.exe

Tag summary

Content type

Image

Digest

Size

1.6 GB

Last updated

almost 7 years ago

docker pull supinf/proxy-container