【问题标题】:Subdomain, virtual host XAMPP子域,虚拟主机 XAMPP
【发布时间】:2015-06-24 08:55:27
【问题描述】:

寻求有关在 XAMPP 中设置子域的帮助。

我读过几篇文章,虽然它们似乎都与本地安装有关,但我拥有的是 XAMPP 的 PORTABLE 版本,因此没有驱动器前缀。

我尝试了下面提到的一些文章,但似乎都没有。他们都显示服务器没有响应或最终去谷歌搜索。

我在 httpd.conf 中有

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

然后在extra/httpd-vhosts.conf中

NameVirtualHost *:80

<VirtualHost *>
    ServerAdmin admin@localhost.com
    ServerName localhost
    ServerAlias localhost
    DocumentRoot "/xampp/htdocs/public"
    <Directory "/xampp/htdocs/public">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost forums*>
    ServerAdmin admin@localhost.com
    ServerName forums
    ServerAlias forums
    DocumentRoot "/xampp/htdocs/public/forums"
    <Directory "/xampp/htdocs/public/forums">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

当我这样做时,“forums.localhost”在 chrome “http://www.forums.localhost/”中变成了这个,然后我得到:

网页不可用

在我阅读的许多内容中,有些人提到编辑 windows 主机文件,但鉴于这是 XAMPP 的便携式版本,我不能总是在每台计算机上编辑主机文件。

这些都是我尝试过的,但都失败了 http://austin.passy.co/2012/setting-up-virtual-hosts-wordpress-multisite-with-xampp-on-windows-7/

https://community.apachefriends.org/f/viewtopic.php?p=198815&sid=7a72729a95ed298148f8635dd414295a

how to create subdomains in apache(xampp) server?

有人可以帮我如何让子域在 PORTABLE 版本上工作,或者我应该如何做,或者编辑 windows 主机文件是强制性的吗?

【问题讨论】:

    标签: php apache xampp


    【解决方案1】:

    未测试,但试试这个:

    NameVirtualHost *:80
    
    <VirtualHost *:80>
        ServerAdmin admin@localhost.com
        ServerName localhost
        ServerAlias localhost
        DocumentRoot /xampp/htdocs/public
        <Directory "/xampp/htdocs/public">
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin admin@localhost.com
        ServerName forums
        ServerAlias forums
        DocumentRoot /xampp/htdocs/public/forums
        <Directory "/xampp/htdocs/public/forums">
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    

    别忘了写

    127.0.0.1 forums
    

    到您的主机文件,如果您没有 DNS 服务器。

    【讨论】:

    • 好的,我完成了上述操作并编辑了主机文件,而不是加载主页,它重定向到论坛文件夹和 500 内部错误“forums.localhost/forums”应该文件夹名称不可见吗?
    • 是的,试试不带子文件夹的“forums.localhost”。因为 DocumentRoot 已经链接到论坛文件夹。 500 内部错误表示虚拟主机已经工作,可能你的 php-script 有错误或类似的东西。
    • ok 刚刚检查过,laravel 对虚拟主机文件夹没有影响。但它仍在重定向。我添加了一个 htaccess 文件并且它有效。没有它,它会重定向到 forums.localhost/forums 并且不会加载 index.html
    【解决方案2】:

    您需要将 forums.localhost 添加到您的主机文件中。

    编辑%SystemRoot%\System32\drivers\etc\hosts并添加127.0.0.1 forums.localhost

    我不认为有其他方法可以做到这一点,抱歉(也许创建一个自动编辑主机文件的脚本,但它很脏)。

    【讨论】:

    • 好的,我完成了上述操作并编辑了主机文件,而不是加载主页,它重定向到论坛文件夹和 500 内部错误“forums.localhost/forums”应该文件夹名称不可见吗?
    • 您是否有.htaccess 文件或重写URL(并在URL 末尾添加“论坛”)的代码?
    • 我有一种感觉,我知道它可能是什么。我在公共场合使用 laravel 文件夹。我想我也许可以在那里安装一个新的子域。但它不适用于 laravel