使用本地 IP 地址访问本地网络上的服务器 Web 服务器

使用本地 IP 地址访问本地网络上的服务器 Web 服务器

我有一台使用 Apache 作为 Node Web 服务请求代理的服务器。我目前能够使用我的域名在本地网络之外的浏览器进行连接:https://mydomain.ca。我相信我用过的能够使用本地网络内的浏览器使用服务器的本地 IP 地址进行连接: 。但是,当我现在尝试时,我收到 500 错误。我正在寻求帮助以使其再次正常工作。如果更可行,https://10.0.0.13我也可以不在本地网络上使用 SSL 并使用 访问服务器。http://10.0.0.13

我收到以下带有 500 错误的文本:

The proxy server could not handle the request 
Reason: Error during SSL Handshake with remote server

我查看了 Apache 错误日志(/var/log/apache2/error.log)以寻找更多线索,但没有找到非常有用的文本:

[Sun Nov 28 23:11:42.609115 2021] [proxy_http:error] [pid 28560:tid 140085584455424] [client 10.0.0.220:26070] AH01097: pass request body failed to 127.0.0.1:4201 (loca lhost) from 10.0.0.220 () 
[Sun Nov 28 23:11:42.769782 2021] [proxy:error] [pid 28560:tid 140085567670016] (20014)Internal error (specific information not available): [client
10.0.0.220:26071] AH 01084: pass request body failed to 127.0.0.1:4201 (localhost) 
[Sun Nov 28 23:11:42.769805 2021] [proxy:error] [pid 28560:tid 140085567670016] [client 10.0.0.220:26071] AH00898: Error during SSL Handshake with remote server returne d by /

我的配置文件如下:

mydomain.ca-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName mydomain.ca
    ServerAlias www.mydomain.ca
    ProxyPreserveHost on
    SSLProxyEngine on
    ProxyPass / https://localhost:4201/
    ProxyPassReverse / https://localhost:4201/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

ServerAlias mydomain.ca
SSLCertificateFile /etc/letsencrypt/live/mydomain.ca/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.ca/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

我的域名.ca.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName mydomain.ca
    ServerAlias www.mydomain.ca
    DocumentRoot /var/www/mydomain.ca
    ProxyPreserveHost on
    ProxyPass / http://localhost:4201/
    ProxyPassReverse / http://localhost:4201/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>

编辑-这里有一些关于 Node Web 服务的信息:Node Web 服务正在监听单个端口,并且只监听 https 连接。

答案1

您已配置 HTTP 和 HTTPS 以连接到后端服务器上的同一端口。

您的后端服务器不太可能在同一端口上支持两种协议。

在两个 VirtualHosts 中都使用 HTTP,或者如果后端服务器同时支持 HTTPS,则使用正确的 HTTPS 端口。

答案2

上面的一些评论让我以正确的方式思考这个问题。我采取的方法是

  • 在我的 Node Web 服务中的不同端口上运行单独的 http 和 https 服务器,
  • 更新 mydomain.ca.conf 和 mydomain.ca-le-ssl.conf 中的端口号,使其与正确的端口号相对应,并且
  • 更新 mydomain.ca.conf 以仅响应来自本地主机或 LAN 的请求,如下所示。
<VirtualHost *:80>
  # We should only access the web server via http if on localhost
  # or within LAN.
  <Location />
    Require local
    Require ip 10.0.0.0/24
  </Location>
  ...

有了这一切,我现在可以http://10.0.0.13从我的本地网络内部和https://mydomain.ca本地网络外部进行访问。

相关内容