微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Apache 向所有虚拟主机提供相同的内容

如何解决Apache 向所有虚拟主机提供相同的内容

我正在运行 ubuntu 服务器 20.04,但在配置 apache 为每个子域提供正确的内容时遇到了一些麻烦。

我有两个子域:

  1. nextcloud.mydomain.com
  2. bitwarden.mydomain.com

Nextcloud 在服务器上本地运行。 Bitwarden 被重定向一个 docker 容器。 无论我做什么,我都会得到nextcloud的内容。 当我为例如添加一个 CNAME 记录时abc.mydomain.com 在 apache 中不是有效的虚拟主机,我也得到了 nextcloud 页面。但是 nextcloud 抱怨通过错误的域访问(当我抑制错误的 SSL 时)。

因为我的服务器在一个动态 IP 后面,所以我的 CNAME 被重定向到另一个域(dynDNS 服务),这导致了我的 IP。也许这是相关的 - 但 nextcloud 抱怨如上所述的错误子域,因此我认为 apache 也应该解决这个问题。

这是我的 Vhosts 配置文件

<VirtualHost *:80>
ServerName nextcloud.mydomain.com
ServerAlias nextcloud-mydomain.dnsupdate.info

DocumentRoot /var/www/nextcloud
ServerPath /nextcloud/

#RewriteEngine on
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<VirtualHost *:443>
ServerName nextcloud.mydomain.com
ServerAlias nextcloud-mydomain.dnsupdate.info

    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>

DocumentRoot /var/www/nextcloud
ServerPath /nextcloud/

SSLEngine on

Include /etc/letsencrypt/options-ssl-apache.conf


Protocols h2 HTTP 1.1
SSLCertificateFile /etc/letsencrypt/live/nextcloud.mydomain.com-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/nextcloud.mydomain.com-0001/privkey.pem
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyRequests Off
    ServerName bitwarden.mydomain.com
    ServerAlias bitwarden-mydomain.dnsupdate.info

    ProxyPass / http://127.0.0.1:10080/
    ProxyPassReverse / http://127.0.0.1:10080/
</VirtualHost>

<VirtualHost *:443>
    ProxyPreserveHost On

    ProxyRequests Off
    ServerName bitwarden.mydomain.com
    ServerAlias bitwarden-mydomain.dnsupdate.info

    ProxyPass / https://127.0.0.1:10443/
    ProxyPassReverse / https://127.0.0.1:10443/
</VirtualHost>

谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。