我正在按照本教程来configurationHAProxy和让我们encryption。 目标是将请求转发到example.com/sensu到在127.0.0.1:3002上监听的服务器实例。 但是当我在浏览器中使用http或https访问example.com/sensu时,我总是得到:
503服务不可用
没有服务器可用来处理这个请求。
为什么我无法通过HAProxy到达服务器?
设置如下:
我的域有一个logging点,我的路由器的公共IP。
服务器的主机位于路由器后面,并分配给一个专用IP(10.0.0.x)。 在路由器上,我将端口80,443上的所有stream量转发到此私有IP(10.0.0.x:80,10.0.x:443),并使用letsencrypt成功生成了我的证书。
在机器上,我有这个服务器,这是一个uchiwa仪表板,在docker容器中运行,并在127.0.0.1:3002
$docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 48889effb2fb uchiwa/uchiwa "/go/bin/uchiwa -c /c" About an hour ago Up About an hour 127.0.0.1:3002->3000/tcp uchiwa
并且可以从主机访问端口:
$ telnet 127.0.0.1 3002 Trying 127.0.0.1... Connected to 127.0.0.1.
HAProxy直接在主机上运行。 这是我的haproxy.cfg
global log /dev/log local0 log /dev/log local1 notice debug chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon maxconn 500 tune.ssl.default-dh-param 2048 # 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-your-web-servers-ssl-ciphers/ ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS ssl-default-bind-options no-sslv3 defaults log global mode http option forwardfor 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 www-http bind :80 reqadd X-Forwarded-Proto:\ http acl uchiwa path_beg /sensu use_backend uchiwa-backend if uchiwa frontend www-https bind :443 ssl crt /etc/haproxy/certs/example.com.pem reqadd X-Forwarded-Proto:\ https acl uchiwa path_beg /sensu acl letsencrypt-acl path_beg /.well-known/acme-challenge/ use_backend uchiwa-backend if uchiwa use_backend letsencrypt-backend if letsencrypt-acl backend uchiwa-backend redirect scheme https if !{ ssl_fc } server 127.0.0.1:3002 check backend letsencrypt-backend server letsencrypt 127.0.0.1:54321
HAproxy日志在启动所有代理服务之后没有任何显示,即使它成功地将我的http请求redirect到https:
Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy www-http started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy www-http started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy www-https started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy www-https started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy uchiwa-backend started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy uchiwa-backend started. Jul 24 16:54:56 <hostmachine> haproxy[18640]: Proxy letsencrypt-backend started. (nothing after this line...)
我也尝试绑定服务器到所有接口(0.0.0.0:3002)。 我哪里做错了? 请帮忙。
================================================== ========
更新:
原来的服务器名称是必填字段。 我更新了我的后端设置,现在我再也看不到503错误了。
backend uchiwa-backend option forceclose redirect scheme https if !{ ssl_fc } server uchiwa 172.17.0.6:3000
但是现在我得到了404错误。
404页面不存在
这里是日志:
Aug 7 03:38:41 <hostmachine> haproxy[723]: 192.168.1.1:57720 [07/Aug/2016:03:38:41.957] www-https~ uchiwa-backend/uchiwa 4/0/0/0/5 404 195 - - ---- 0/0/0/0/0 0/0 "GET /sensu HTTP/1.1" Aug 7 03:38:42 <hostmachine> haproxy[723]: 192.168.1.1:57721 [07/Aug/2016:03:38:42.293] www-https~ www-https/<NOSRV> -1/-1/-1/-1/3 503 213 - - SC-- 0/0/0/0/0 0/0 "GET /favicon.ico HTTP/1.1"
您在unchiwa后端缺less一个服务器名称:
server 127.0.0.1:3002 check
这应该是这样的:
server uchiwa 127.0.0.1:3002 check