AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 930409
Accepted
maar
maar
Asked: 2018-09-12 04:43:14 +0800 CST2018-09-12 04:43:14 +0800 CST 2018-09-12 04:43:14 +0800 CST

SharePoint - HAProxy 反向代理(SSL 问题)

  • 772

下面更新

________________

我决定使用 HAProxy 作为 SharePoint 网站的反向代理,没有 SSL 一切正常,但使用 SSL 我无法启动 haproxy.service。我尝试了许多配置,但我无法弄清楚......

尝试启动服务:

$ sudo systemctl start haproxy.service
Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.

haproxy.service 的状态:

$ sudo systemctl status haproxy.service
     haproxy.service - HAProxy Load Balancer
       Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since date CEST;
         Docs: man:haproxy(1)
               file:/usr/share/doc/haproxy/configuration.txt.gz
      Process: ExecStart=/usr/sbin/haproxy-systemd-wrapper -f $CONFIG -p $PIDFILE $EXTRAOPTS (code=exited, status=0/SUCCESS)
      Process: ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=1/FAILURE)
     Main PID: (code=exited, status=0/SUCCESS)
 systemd[1]: haproxy.service: Failed with result 'exit-code'.
 systemd[1]: haproxy.service: Service hold-off time over, scheduling restart.
 systemd[1]: Stopped HAProxy Load Balancer.
 systemd[1]: haproxy.service: Start request repeated too quickly.
 systemd[1]: Failed to start HAProxy Load Balancer.
 systemd[1]: haproxy.service: Unit entered failed state.
 systemd[1]: haproxy.service: Failed with result 'exit-code'.
 systemd[1]: haproxy.service: Start request repeated too quickly.
 systemd[1]: Failed to start HAProxy Load Balancer.
 systemd[1]: haproxy.service: Failed with result 'exit-code'.

检查配置文件问题:

$ sudo haproxy -c -f haproxy.cfg
    Enter PEM pass phrase:
    [ALERT]: parsing [haproxy.cfg:31] : 'bind *:443' : unable to load SSL private key from PEM file './cert.pem'.
    [ALERT]: Error(s) found in configuration file : haproxy.cfg
    [ALERT]: Proxy 'http_id': no SSL certificate specified for bind '*:443' at [haproxy.cfg:31] (use 'crt').    
    [ALERT]: Fatal errors found in configuration.

HAProxy -vv:

$ sudo haproxy -vv
HA-Proxy version 1.7.5-2

Encrypted password support via crypt(3): yes
Built with zlib version : 1.2.8
Running on zlib version : 1.2.8
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with OpenSSL version : OpenSSL 1.1.0e
Running on OpenSSL version : OpenSSL 1.1.0f
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports prefer-server-ciphers : yes
Built with PCRE version : 8.39
Running on PCRE version : 8.39
PCRE library supports JIT : no (USE_PCRE_JIT not set)
Built with Lua version : Lua 5.3.3
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with network namespace support

Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 3 (3 usable), will use epoll.

Available filters :
        [COMP] compression
        [TRACE] trace
        [SPOE] spoe

日志:

 haproxy: [ALERT]: parsing [/etc/haproxy/haproxy.cfg:31] : 'bind *:443' : unable to load SSL certificate file './cert.pem' file does not exist.
 haproxy: [ALERT]: Error(s) found in configuration file : /etc/haproxy/.cfg
 haproxy: [ALERT]: Proxy 'http_id': no SSL certificate specified for bind '*:443' at [/etc/haproxy/haproxy.cfg:31] (use 'crt').
 haproxy: [ALERT]: Fatal errors found in configuration.

我在另一台服务器上为 nginx 使用相同的证书(但分为:证书、密钥、链),它可以工作。我用命令为 HAProxy 创建了这个cat cert.crt priv.key certchain.crt > cert.pem,我尝试了不同的顺序,但错误是一样的。命令haproxy -c -f haproxy.cfg服务器也询问密码,所以我认为证书没问题(也许我错了)并且配置文件有问题。感谢您的时间和帮助。

我的 haproxy.cfg:

    global    
        tune.ssl.default-dh-param 2048
        maxconn 4096
        user haproxy
        group haproxy
        daemon
        #ssl-server-verify none
    
    defaults
        mode http
        option forwardfor
        log 127.0.0.1 local0 notice
        maxconn 2000
        option httplog
        option dontlognull
        timeout connect 5000
        timeout client 50000
        timeout server 50000
            
    backend sharepoint
        mode http
        #balance roundrobin
        option redispatch
        cookie SERVERID insert nocache
        server spsrv xxx.xxx.xxx.xxx:80
            
    frontend http_id
        #bind *:80
        bind *:443 ssl crt ./cert.pem
        mode http
        reqadd X-Forwarded-Proto:\ https
        acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com:443
        use_backend sharepoint if hosts_sharepoint
        default_backend sharepoint

第一次更新

我尝试了直通,现在 SharePoint 在端口 80 上请求凭据(在禁用 IIS 角色之后),然后 SharePoint 重定向到 https 并出现错误“504 网关超时”。这是我当前的 haproxy.cfg:

global
    maxconn 4096
    user haproxy
    group haproxy
    daemon
defaults
    mode tcp
    log 127.0.0.1 local0 notice
    maxconn 2000
    option tcplog
    option dontlognull
    timeout connect 20s
    timeout client 10m
    timeout server 10m
frontend httpid
    mode tcp
    bind *:443
    acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
    use_backend sharepoint if hosts_sharepoint
    default_backend sharepoint
backend sharepoint
    mode tcp
    balance roundrobin
    option redispatch
    cookie SERVERID insert indirect nocache
    server st1 xxx.xxx.xxx.xxx:443
    option ssl-hello-chk

同样 command: $ curl xxx.xxx.xxx.xxx:**80** --header 'Host: sharepoint.intranet.com' -vv返回 401 ,因此连接正常,但是带有端口 443 的命令$ url xxx.xxx.xxx.xxx:**443** --header 'Host: sharepoint.intranet.com' -vv返回curl: (56) Recv failure: Connection reset by peer. 我的配置文件正确吗?或者也许我需要配置 IIS?

第二次更新

重新启动 SharePoint 服务器后,此配置正在使用pass-through:

global
    maxconn 4096
    user haproxy
    group haproxy
    daemon
defaults
    mode tcp
    log 127.0.0.1 local0 notice
    maxconn 2000
    option tcplog
    option dontlognull
    timeout connect 20s
    timeout client 10m
    timeout server 10m
frontend httpid
    mode tcp
    bind *:443
    acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
    use_backend sharepoint if hosts_sharepoint
    default_backend sharepoint
backend sharepoint
    mode tcp
    balance roundrobin
    option redispatch
    cookie SERVERID insert indirect nocache
    server st1 xxx.xxx.xxx.xxx:443
    option ssl-hello-chk
ssl
  • 2 2 个回答
  • 3261 Views

2 个回答

  • Voted
  1. NuTTyX
    2018-09-12T08:59:38+08:002018-09-12T08:59:38+08:00

    您应该避免在配置文件中使用相对路径,例如./cert.pem. 请改成绝对路径之类的/etc/ssl/cert.pem(调整为当前路径)。

    另外,检查cert.pem文件本身。它应该只包含可打印的文本(不是二进制),至少包含两个-----BEGIN CERTIFICATE-----,-----END CERTIFICATE-----块(您的证书和链中的 CA)和一个-----BEGIN PRIVATE KEY-----,-----END PRIVATE KEY-----块(或者可能是一个-----BEGIN RSA PRIVATE KEY-----, -----END RSA PRIVATE KEY-----)。

    如果文件中有任何二进制cert.pem文件,您应该将原始文件 ( cert.crt, priv.key) 转换为 PEM 格式并重新创建cert.pem文件。连接的正确顺序应该是最终证书、密钥、直接颁发者、下一个颁发者等。您可以省略根 CA,因为不包括它被认为是一种好习惯(没有真正需要,交换的字节数更少)。

    您可以使用 openssl 从二进制格式(又名 DER)转换为文本格式(又名 PEM):

    对于证书(input.crt将是 DER 文件,并且output.crt将是 PEM 格式的新文件):

    openssl x509 -inform DER -in input.crt -out output.crt

    对于密钥(我假设它是 RSA 密钥,这是最常用的)注意:它会要求输入(新)密码output.key,请参阅我稍后对此的评论。

    openssl rsa -inform DER -in input.key -out output.key

    注意:大多数服务器假定密钥没有加密(即-----BEGIN PRIVATE KEY-----contains的下一行ENCRYPTED)。如果是这种情况并且您的服务器仍然无法启动,请尝试将密钥转换为未加密的格式(注意:在此命令中,我假设inputcipher.key文件已经是 PEM 格式):

    openssl rsa -in inputcipher.key -nodes -out outputclear.key

    至于错误的传递504,在后面的配置中你指向的是,server st1 xxx.xxx.xxx.xxx:443而在拦截配置中你指向的是server spsrv xxx.xxx.xxx.xxx:80. 请重新检查一下你的后端是监听80端口还是443端口,但是443似乎没有后端监听。

    • 1
  2. Best Answer
    maar
    2018-09-18T03:30:29+08:002018-09-18T03:30:29+08:00

    也许它会对某人有所帮助。就我而言,我在 Linux 上配置了两个网络适配器——本地网络和公共网络。在 Windows 上,我只有本地网络 - Windows 在本地网络中与 Linux 连接,然后通过 HAProxy,我可以从 Internet 打开 SharePoint 站点。

    这是正确的配置,在我的情况下有效(对于 SSL,我使用了直通 - 重定向和证书在 Windows IIS 上):

    global
        maxconn 4096
        user haproxy
        group haproxy
        daemon
    defaults
        mode tcp
        log 127.0.0.1 local0 notice
        maxconn 2000
        option tcplog
        option dontlognull
        timeout connect 20s
        timeout client 10m
        timeout server 10m
    frontend httpid
        mode tcp
        bind *:443
        acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
        use_backend sharepoint if hosts_sharepoint
        default_backend sharepoint
    backend sharepoint
        mode tcp
        balance roundrobin
        option redispatch
        server st1 xxx.xxx.xxx.xxx:443 #local address of the Windows server
        option ssl-hello-chk
    
    • 0

相关问题

  • 如何使用 Tomcat 5.5 更新 SSL 证书

  • 为 IIS6 自行生成 SSL 证书?

  • plesk 上的域和子域 ssl 访问

  • 如何设置 SSL 邮件服务器?

  • 如何通过 SVN 命令行接受 SSL 证书?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve