Admin

【教程】Docker快速部署SNIProxy

如题,官网没有提供编译好的release挺烦人的,又不像编译安装
可使用Docker进行部署,基于alpine镜像,吃的资源很少

FROM alpine:3.6

RUN set -x \
    && apk add --update sniproxy \
    && rm -rf /var/cache/apk/*

WORKDIR /etc/sniproxy

EXPOSE 443

CMD ["/usr/sbin/sniproxy","-c","/etc/sniproxy/sniproxy.conf","-f"]

构建镜像:

docker build --tag sniproxy .

运行:

docker run -d -p 443:443 -p 80:80 -v [your conf path]:/etc/sniproxy/sniproxy.conf sniproxy

sniproxy.conf 样例

# sniproxy example configuration file
# lines that start with # are comments
# lines with only white space are ignored

user daemon

# PID file
pidfile /var/run/sniproxy.pid

error_log {
    # Log to the daemon syslog facility
    syslog deamon

    # Alternatively we could log to file
    #filename /var/log/sniproxy/sniproxy.log

    # Control the verbosity of the log
    priority notice
}

# blocks are delimited with {...}
listen 80 {
    proto http
    table http_hosts
    # Fallback backend server to use if we can not parse the client request
    fallback localhost:8080

    access_log {
        filename /var/log/sniproxy/http_access.log
        priority notice
    }
}

listen 443 {
    proto tls
    table https_hosts

    access_log {
        filename /var/log/sniproxy/https_access.log
        priority notice
    }
}

# named tables are defined with the table directive
table http_hosts {
    example.com 192.0.2.10:8001
    example.net 192.0.2.10:8002
    example.org 192.0.2.10:8003

# pattern:
#   valid Perl-compatible Regular Expression that matches the
#   hostname
#
# target:
#   - a DNS name
#   - an IP address (with optional port)
#   - '*' to use the hostname that the client requested
#
# pattern   target
#.*\.itunes\.apple\.com$    *:443
#.* 127.0.0.1:4443
}

# named tables are defined with the table directive
table https_hosts {
    # When proxying to local sockets you should use different tables since the
    # local socket server most likely will not autodetect which protocol is
    # being used
    example.org unix:/var/run/server.sock
}

# if no table specified the default 'default' table is defined
table {
    # if no port is specified default HTTP (80) and HTTPS (443) ports are
    # assumed based on the protocol of the listen block using this table
    example.com 192.0.2.10
    example.net 192.0.2.20
}

参考: