Apache2的虚拟主机有两个子目录配置 [英] apache2 virtualhost configuration with two subdirectories

查看:227
本文介绍了Apache2的虚拟主机有两个子目录配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Ubuntu 14.04服务器上运行的Apache 2.4。它的目的是邮件服务器,所以它有它后缀,达夫科特和roundcube(除其他事项外)。我想,和失败,配置Apache服务我想要的页面。

I'm running Apache 2.4 on Ubuntu 14.04 server. It's purpose is a mail server so it has postfix, dovecot and roundcube on it (amongst other things). I'm trying, and failing, to configure Apache to serve the pages that I want.

我安装了SSL证书,并正常工作。我要强制通过HTTPS所有访问,所以我有:

I have an SSL certificate installed and working correctly. I want to force all access over HTTPS so I have:

<VirtualHost *:80>
    Redirect / https://mailserver.hni.ae/
</VirtualHost>

送达文件的两套正在的/ var / www / html等,第一个是的/ var / www / html等/ A 和其他的/ var / www / html等/ B (比方说)。我已经配置我的 /etc/apache2/sites-available/000-default.conf (其中有一个符号链接 ./启用的站点 - )是:

Both sets of files to be served are under /var/www/html, the first being /var/www/html/A and the other /var/www/html/B (let's say). I have configured my /etc/apache2/sites-available/000-default.conf (which has a symlink to ./sites-enabled) to be:

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile      /etc/ssl/private/mycert.crt
    SSLCertificateKeyFile   /etc/ssl/private/mycert.key

    ServerAdmin webmaster@mydomain.com
    ServerName www.mydomain.com
    DocumentRoot /var/www/html/
    DirectoryIndex index.php

    <Directory /var/www/html/A>
      Options FollowSymLinks
      AllowOverride None
      Order Allow,Deny
      Allow from all
    </Directory>

    <Directory /var/www/html/B>
      Options FollowSymLinks
       AllowOverride None
       Order Deny,Allow
       Deny from All
       Allow from 192.168.1.1
    </Directory>

    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

和工程。我可以去 www.mydomain.com/B 与其所服务的登录页面的网页(只有当我从指定的IP地址访问),而 www.mydomain.com/A 并登录到应用程序从一个页面。

And that works. I can go to www.mydomain.com/B and it serves the login page for those pages (only when I access from the specified IP address), and www.mydomain.com/A and login to the pages from app A.

我的问题:我希望能够去 www.mydomain.com/C 只是普通的 www.mydomain.com 并重定向到 www.mydomain.com/A 但是当我使用重定向... 服务器进入一个循环,并尝试以服务 www.mydomain.com/AAAAAAA ... 。我怀疑我应该使用 RedirectMatch临时^ / $ ... 指令,但不能得到这工作的。也许是与在重定向 80 :443 冲突?没有的.htaccess 参与其中我使用的AllowOverride无

My problem: I want to be able to go to www.mydomain.com/C and just plain www.mydomain.com and be redirected to www.mydomain.com/A but when I use Redirect ... the server gets into a loop and tries to serve www.mydomain.com/AAAAAAA.... I suspect I should use the RedirectMatch temp ^/$... directive but can't get that to work either. Maybe something to do with the Redirect for :80 to :443 clashing? There is no .htaccess involved as I'm using AllowOverride None.

我读过了Apache 2.4的文档彻底,但就是无法弄清楚。有什么建议?

I've read the Apache 2.4 documentation thoroughly but just can't figure it out. Any suggestions?

推荐答案

您可以使用重写规则。添加到您的虚拟主机:

You can use a RewriteRule. Add this to your VirtualHost:

RewriteEngine On
RewriteRule ^/(C/?|)$ /A [R,L]

确认的mod_rewrite 已启用了。

说明:
正则表达式 ^ /(C / |?)$ 将匹配 / C 后面可以跟一个 / ,或只是 / 即www.mydomain.com

Explanation: Regex ^/(C/?|)$ will match /C optionally followed by a /, or just / i.e. the root of www.mydomain.com

这篇关于Apache2的虚拟主机有两个子目录配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆