在 xampp localhost 中创建通配符子域
Posted
技术标签:
【中文标题】在 xampp localhost 中创建通配符子域【英文标题】:Create wildcard subdomain in xampp localhost 【发布时间】:2017-01-05 00:43:33 【问题描述】:我正在尝试在xampp
中创建wildcard subdomain
,用于我在本地开发Laravel
项目。到目前为止,我能够更改主机文件并为我的域名创建一个虚拟主机。
这是我的主机文件
127.0.0.1 localhost
127.0.1.1 lalit-Inspiron-3537
127.0.0.1 mysite.local
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02:
:2 ip6-allrouters
我在httpd.conf
文件中启用了虚拟主机
这是我的 httpd-vhosts.conf 文件
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/opt/lampp/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/mysite/public"
ServerName mysite.local
ServerAlias *.mysite.local
<Directory "/opt/lampp/htdocs/mysite/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我可以通过mysite.local
访问我的Laravel
项目。但是当我尝试访问subdomain.mysite.local
时出现以下错误
This site can’t be reached
subdomain.mysite.local’s server DNS address could not be found.
Try:
Checking the connection
Checking the proxy, firewall, and DNS configuration
ERR_NAME_NOT_RESOLVED
谁能帮我解决这个问题?
【问题讨论】:
【参考方案1】:我找到了解决方案。事实证明,我们不能使用.local
作为我们的域名,因为它被avahi-daemon
使用。所以我从我的域名中更改了.local
,
主机文件
127.0.0.1 localhost
127.0.1.1 lalit-Inspiron-3537
127.0.0.1 mysite.dev
httpd-vhosts.conf 文件
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/mysite/public"
ServerName mysite.local
ServerAlias *.mysite.local
<Directory "/opt/lampp/htdocs/mysite/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
现在它运行良好。
【讨论】:
您的ServerName
和 ServerAlias
指令仍然指向 mysite.local
。
是的,这就是重点。我试图将每个请求重定向到同一目录,并根据我的 Laravel
项目中的 subdomain
文本处理它们。以上是关于在 xampp localhost 中创建通配符子域的主要内容,如果未能解决你的问题,请参考以下文章
xampp 开发:在 htdocs 文件夹中创建项目(文件夹和文件)