当存在多个虚拟主机标签时,Apache 2.4.7 重定向不起作用 Ubuntu14.04

     2023-03-10     249

关键词:

【中文标题】当存在多个虚拟主机标签时,Apache 2.4.7 重定向不起作用 Ubuntu14.04【英文标题】:Apache 2.4.7 redirect not working when multiple Virtual host tags are present Ubuntu14.04 【发布时间】:2016-04-13 06:53:29 【问题描述】:

我的 conf 文件中有 2 个虚拟主机标签。

第一个标签包含来自内部 IP 地址的请求的重定向规则。

第二个标签包含来自公共 IP 或任何其他地方的请求的其他重定向规则

当我删除第一个 VirtualHost 标记时,重定向和 ssl 工作得非常好,但我还需要第一个 VirtualHost 标记

我的配置文件

这位于 /etc/apache2/sites-available/site.conf

<VirtualHost 10.1.0.7:80>
    ProxyPreserveHost On
    LogLevel debug
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined
    ServerName servername.com
    ProxyPass /Service http://localhost:8080/Service
    ProxyPassReverse /Service http://localhost:8080/Service
</VirtualHost>
<VirtualHost *:80>
    ProxyPreserveHost On
    LogLevel debug
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined
    ServerName servername.com
    RewriteEngine On    # Turn on the rewriting engine
    RewriteCond %HTTPS !=on
    RewriteRule ^/?(.*) https://%SERVER_NAME/$1 [R,L] 
</VirtualHost>

如果我删除第一个包含私有 IP 的 VirtualHost 标记,一切正常,但只要我添加它,服务器就不会重定向到 443 端口。

我的 ssl 配置文件:

位于 /etc/apache2/sites-available/site-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html
    LogLevel debug
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined
     ProxyPreserveHost On
        ServerName server.com
    # Redirections:
    ProxyPass /server-status http://localhost:7570/server-status
    ProxyPassReverse /server-status http://localhost:7570/server-status

    ProxyPass /mCare/subscribe ws://localhost:8080/mCare/subscribe
    ProxyPassReverse /mCare/subscribe ws://localhost:8080/mCare/subscribe

    ProxyPass /mCare http://localhost:8080/mCare
    ProxyPassReverse /mCare http://localhost:8080/mCare

    ProxyPass /solr http://localhost:8280/solr
    ProxyPassReverse /solr http://localhost:8280/solr

    SSLEngine on
            SSLCertificateFile      /mnt/opt/ssl/2015/sha2/b89516b0cdc9a701.crt
            SSLCertificateKeyFile   /mnt/opt/ssl/2015/sha2/mcare.pem
            SSLCertificateChainFile /mnt/opt/ssl/2015/sha2/gd_bundle.crt

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>

这是我的 ports.conf 文件:

Listen 80

<IfModule ssl_module>
      Listen 443
</IfModule>

我也创建了所有需要的软链接。

【问题讨论】:

【参考方案1】:

我终于让它工作了。

我发布此内容是为了让面临相同问题的其他人可以得到帮助。

我只是用服务器的内部IP避免了虚拟主机标签,并设法在RewriteRule中编写了更好的正则表达式

<VirtualHost *:80>
    ProxyPreserveHost On

    ProxyPass /Service http://localhost:8080/Service
    ProxyPassReverse /Service http://localhost:8080/Service





    LogLevel debug
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined


    ServerName server.com

    RewriteEngine On    # Turn on the rewriting engine
    RewriteCond %HTTPS !=on

    RewriteRule ^((?!/Service).)*$ https://%SERVER_NAME%REQUEST_URI [R,L]

</VirtualHost>

所以现在,我的 /etc/apache2/sites-available/site.conf 文件只包含一个虚拟标签。

我已经编写了表达式,以便包含 Service 的所有请求都不需要重定向到 https,并且我也为此提供了 proxyPass。

这解决了我的问题

如果有人有更好的解决方案,那么也欢迎您的回答

【讨论】:

仅当本地目录不存在时才在 Apache 中使用别名?

】仅当本地目录不存在时才在Apache中使用别名?【英文标题】:UsingAliasinApacheONLYiflocaldirectorynotpresent?【发布时间】:2010-09-2922:16:09【问题描述】:我们正在运行一个经销商网络主机,并为其中的所有网站设置一个特定目录的别... 查看详情

在 PHP7 Apache/2.4.7 (Ubuntu) 上安装 phpmyadmin 时遇到问题

】在PHP7Apache/2.4.7(Ubuntu)上安装phpmyadmin时遇到问题【英文标题】:HavetroubleinstallingphpmyadminonPHP7Apache/2.4.7(Ubuntu)【发布时间】:2016-03-0717:09:51【问题描述】:我今天安装了PHP7sudoadd-apt-repositoryppa:ondrej/php-7.0sudoapt-getinstallphp7.0-cliph 查看详情

php - 在 Windows 7 上的 PHP7 Apache/2.4.7 上安装 phpmyadmin 时遇到问题

】php-在Windows7上的PHP7Apache/2.4.7上安装phpmyadmin时遇到问题【英文标题】:php-HavetroubleinstallingphpmyadminonPHP7Apache/2.4.7onwindows7【发布时间】:2016-09-1120:53:18【问题描述】:致命错误:未捕获错误:调用C:\\Apache24\\htdocs\\phpMyAdmin\\libraries... 查看详情

为 Apache 虚拟主机设置多个域时出错

】为Apache虚拟主机设置多个域时出错【英文标题】:ErrorsettingseveraldomainsforApacheVirtualHost【发布时间】:2021-12-2916:18:02【问题描述】:我已经为多个域创建了一个Apache虚拟主机。我用创建了domain.conf文件ServerNamewww.hrvendurance.comServer... 查看详情

当虚拟主机指向 HTDOCS 之外时,Apache 会中断 laravel 路由

】当虚拟主机指向HTDOCS之外时,Apache会中断laravel路由【英文标题】:ApachebreakslaravelrouteswhenvirtualhostpointsoutsideHTDOCS【发布时间】:2018-07-1915:08:52【问题描述】:我正在尝试将我的Laravel5.5项目迁移到Apache。问题是,当我创建一个... 查看详情

在 Mint 15 上使用 Apache2 设置多个虚拟主机时出错

】在Mint15上使用Apache2设置多个虚拟主机时出错【英文标题】:ErrorsettingupmultiplevhostswithApache2onMint15【发布时间】:2013-09-0520:29:33【问题描述】:我刚刚在mint15上安装了Apache2。我能够看到localhost,因此决定为我的项目添加虚拟主... 查看详情

阿帕奇服务器 2.4.7

】阿帕奇服务器2.4.7【英文标题】:Apacheserver2.4.7【发布时间】:2017-02-1713:04:32【问题描述】:当我在Apache/2.4.7(ubuntu)中运行我的第一个程序时,它显示如下错误:未找到在此服务器上未找到请求的URL/hello。Apache/2.4.7(Ubuntu)服务器... 查看详情

apache2虚拟主机实现一个服务器绑定多个域名

...名的解析将全部域名的www和@的A记录解析到云服务器的IP3.虚拟主机的配置1.配置httpd.conf如果etc/httpd/conf/httpd.conf存在,则配置此httpd.conf如果etc/httpd/conf/httpd.conf不存在,此时需要我们在/etc/apache2下新 查看详情

当标签已经存在于远程时​​,Git 强制推送标签

】当标签已经存在于远程时​​,Git强制推送标签【英文标题】:Gitforcepushtagwhenthetagalreadyexistsonremote【发布时间】:2014-11-0701:35:26【问题描述】:我已经将标签推送到遥控器上。当另一个用户创建相同的标签并尝试推送时,推... 查看详情

当标签没有值但属性存在时,需要 XSLT 删除标签

】当标签没有值但属性存在时,需要XSLT删除标签【英文标题】:NeedXSLTtoremovethetagwhenithasnovaluebutattributeexists【发布时间】:2020-12-2402:24:03【问题描述】:我有XSLT,如果它们的值为空/null,它可以很好地删除标签。但我无法删除具... 查看详情

当默认虚拟主机不可用时,没有虚拟主机可用

】当默认虚拟主机不可用时,没有虚拟主机可用【英文标题】:Whendefaultvirtualhostisnotavailable,novirtualhostsareavailable【发布时间】:2013-10-1519:40:09【问题描述】:我有一个apache2实例代理对多个tomcat实例的请求。有时默认虚拟主机没... 查看详情

mac为apache2服务器配置多个虚拟主机

MAC为Apache2服务器配置多个虚拟主机当我们在做项目的时候有时候有时候需要同时操作多个项目,但是apache服务器默认值只提供一个根目录,这时候就比较麻烦了,我们可以通配置多个虚拟主机来实现这个问题1.先编辑apache2的配... 查看详情

DocumentRoot 没有改变,从 Apache2 2.2.22 更新到 2.4.7

】DocumentRoot没有改变,从Apache22.2.22更新到2.4.7【英文标题】:DocumentRootisnotchanged,UpdatefromApache22.2.22to2.4.7【发布时间】:2014-06-2416:16:38【问题描述】:我确实有以下问题。我已经将一些具有相同层次结构和网站结构的网站移到了... 查看详情

当存在多个网络接口时,可访问性框架在检测接口类型时无法正常工作

】当存在多个网络接口时,可访问性框架在检测接口类型时无法正常工作【英文标题】:Reachabilityframeworkisnotworkingfinewhiledetectinginterfacetypewhenthereismultiplenetworkinterface【发布时间】:2014-10-2001:54:21【问题描述】:我正在使用可达性... 查看详情

在 Ubuntu 上从 Apache 2.4.7 提供降价服务

】在Ubuntu上从Apache2.4.7提供降价服务【英文标题】:ServingmarkdownfromApache2.4.7onUbuntu【发布时间】:2015-12-1208:58:39【问题描述】:我正在运行Apache/2.4.7(Ubuntu14.04.3LTS)并尝试访问.md文件并将其查看为Markdown文件格式。如果我当前将浏览... 查看详情

在 Apache 2.4.7 (ubuntu) 上设置服务器缓存

】在Apache2.4.7(ubuntu)上设置服务器缓存【英文标题】:SettingupservercacheonApache2.4.7(ubuntu)【发布时间】:2015-04-2709:16:48【问题描述】:在Apache2.4上设置服务器缓存的最佳方法是什么?我搜索了互联网并找到了一些特定于Apache2.2的资源... 查看详情

当元素包含多个类名时如何在硒中复制标签?

】当元素包含多个类名时如何在硒中复制标签?【英文标题】:Howtocopytagsinseleniumwhenelementcontainsmultipleclassnames?【发布时间】:2022-01-1712:20:00【问题描述】:从“查看更多”标签下隐藏大量文本的网站抓取数据。通过selenium点击所... 查看详情

.htaccess 未在 Ubuntu 14.04 (Apache 2.4.7) 中加载

】.htaccess未在Ubuntu14.04(Apache2.4.7)中加载【英文标题】:.htaccessnotbeingloadedinUbuntu14.04(Apache2.4.7)【发布时间】:2014-11-0702:18:21【问题描述】:我正在尝试在Ubuntu14.04(Apache2.4.7)中使用.htaccess文件。这是我的.htaccess的样子#1YEAR<FilesMatch... 查看详情