ДА, не вопрос.
Ставим haproxy (есть в любом linux дистрибутиве). помним, что трафик нужно на эту программы натравливать, и порты должны быть свободными.
Пишем такой конфиг:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
#
https://hynek.me/articles/hardening-you ... l-ciphers/
# An alternative list with additional directives can be obtained from
#
https://mozilla.github.io/server-side-t ... er=haproxy
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
# собственно описание настройки
frontend check_afanasy
bind *:51000
mode tcp
log global
option tcplog
timeout client 5000s
maxconn 1000
# куда переходим по дефолту
default_backend get_json
tcp-request inspect-delay 2s
# проверяем запрос от клиента - если html -то по правилу, если json - то по дефолту
acl request_html hdr_beg(Accept) -i text/html
tcp-request content reject if METH_POST request_html
use_backend 404_no_html if request_html
#дефолтный переход
backend get_json
balance source
mode tcp
log global
option tcplog
timeout connect 4s
timeout server 5000s
server afony 192.168.1.110:51000
# переход со сгенерированной ошибкой - html сервера нет
backend 404_no_html
mode http
timeout tarpit 2s
errorfile 500 /etc/haproxy/errors/500.http
# http-request tarpit
Это сделано у нас.
Чтобы сделать basic-аутификацию
нужно перед frontend check_afanasy внести:
userlist UsersFor_cgru
user joe insecure-password letmein
во фронтэнд внести:
acl AuthOkay_AcmeCorp http_auth(UsersFor_cgru)
http-request deny if !UsersFor_cgru
use_backend 404_no_html if request_html !UsersFor_cgru
В таком случае - если пароль работает, то перейдем на дефаулт (по порту 51000)
Если не правльно пройдена аутифкация - то пойдем по 404.
Как-то так.