【问题标题】:Apache HTTPD: How to setup Virtual Host correctlyApache HTTPD:如何正确设置虚拟主机
【发布时间】:2021-04-17 15:18:33
【问题描述】:

我已经在我的 Mac 上安装了 Apache httpd 并且“它工作正常”。

现在我需要配置一个虚拟主机,以便将我的应用程序 (Java Spring) 与 httpd 作为反向代理公开。

这就是我在 /usr/local/etc/httpd/extra/httpd-vhosts.conf 文件中的内容

<VirtualHost *:443>
   ServerName my.domain.it:443
    SSLEngine on
    SSLCertificateFile /path/to/cert.crt
    SSLCertificateKeyFile /path/to/cert.key
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/myapp
    ProxyPassReverse / http://localhost:8080/myapp
</VirtualHost>

/etc/hosts我已经通过这种方式映射到服务器地址:

127.0.0.1       my.domain.it

Tomcat 连接器配置为:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" proxyPort="443" scheme="https"/>

如果我使用 Eclipse 运行应用程序,它会在 http://localhost:8080/myapp/ 正确响应,但如果我尝试调用 https://my.domain.it/myapp/ 它不起作用,Google Chrome 会告诉我:“这个站点不能到达”。

我的配置有什么问题?

附: httpd Apache 实例配置为侦听端口 80

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

谢谢。

编辑:已解决 不幸的是,我无法使用 Apache Httpd 解决,但现在使用 Nginx 可以解决问题。谢谢你的回答

【问题讨论】:

  • 首先检查服务器是否在 127.0.0.1:443 监听。如果没有,请检查服务器是否已启动。还要检查服务器的错误日志。

标签: apache reverse-proxy virtualhost httpd.conf


【解决方案1】:

在 mod_ssl.conf 中(文件名可能不同)你应该有以下行

Listen 443

它告诉 apache 侦听端口 443(当您安装 mod_ssl 以便能够通过 HTTPS 公开您的站点时,它包含在配置文件中)。 同一个配置文件应该包含所有关于 TLS 的共享配置。

如果 apache 正在运行,您可以使用 netstat 检查端口 443 是否正在侦听:

netstat -an | grep -i list

输出应包括端口 80 和 443(以及其他一些取决于服务器上运行的服务,例如 ssh)。

如果端口显示在列表中,下一步是检查 apache 日志是否有错误。

【讨论】:

    猜你喜欢
    • 2017-05-30
    • 2013-07-31
    • 1970-01-01
    • 2014-06-19
    • 2013-01-27
    • 2012-04-22
    • 1970-01-01
    • 2014-11-13
    • 2010-10-23
    相关资源
    最近更新 更多