AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1016134
Accepted
Muhammad Dyas Yaskur
Muhammad Dyas Yaskur
Asked: 2020-05-08 07:22:33 +0800 CST2020-05-08 07:22:33 +0800 CST 2020-05-08 07:22:33 +0800 CST

apache 2.4中子域的通配符子域

  • 772

目前我已经使用如下通配符子域配置:

<VirtualHost *:80>
    ServerAlias *.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

但如果我输入 sub.sub.domain 将返回默认虚拟主机。如何配置到主/根域的路径?我在conf下尝试过,但仍然没有奏效:

<VirtualHost *:80>
    ServerAlias *.*.domain
    ErrorLog /tmp/error.log
    CustomLog /tmp/access.log combined
    VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

我将 %2 更改为 %1 仍然不起作用。

什么是正确的语法?

subdomain virtualhost domain apache-2.4
  • 1 1 个回答
  • 118 Views

1 个回答

  • Voted
  1. Best Answer
    Muhammad Dyas Yaskur
    2020-05-08T14:26:02+08:002020-05-08T14:26:02+08:00

    经过几个小时的解决方法,实际上上面的代码有正确的语法,但我只是把它放在错误的位置顺序。所以正确的答案是把第二个放在第一个上面。

    下面是完整的配置示例:

    <VirtualHost *:80>
        ServerAlias *.*.domain
        ErrorLog /tmp/error.log
        CustomLog /tmp/access.log combined
        VirtualDocumentRoot /var/www/%2/public
    <Directory "/var/www">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAlias *.domain
        ErrorLog /tmp/error.log
        CustomLog /tmp/access.log combined
        VirtualDocumentRoot /var/www/%1/public
    <Directory "/var/www">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    </VirtualHost>
    

    Apache 通过从顶部升序跳过相同的子域/域配置。sub.sub.domain 也是 *.domain 的一部分,所以如果我想配置它,我必须将配置放在顶部,或者如果使用不同的文件配置使用较小的数字名称。

    • 0

相关问题

  • Apache 上的子域不工作 - 找不到服务器

  • 如何使用域经销商 API 设置域屏蔽?

  • 如何在 IIS7 中创建子域?

  • 通配符 DNS 和子域

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve