Apache:虚拟主机配置
当我尝试在 apache 中配置我的虚拟主机时。我放了这样的东西,
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
在我的主机文件中我放了这样的东西,
127.0.0.1 localhost
127.0.0.1 gift.loc
然后在浏览器上运行它,
http://gift.loc - is fine
但是当我尝试使用它时,
http://localhost/othersite - can't found
我是否错过了一些配置?任何想法...
提前致谢,
As i tried to configure my virtual host in apache. I put something like this,
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
And in my hosts file i put something like this,
127.0.0.1 localhost
127.0.0.1 gift.loc
And i run it on the browser,
http://gift.loc - is fine
But when i tried using this,
http://localhost/othersite - can't found
Do i missed somehting to configure? ANy ideas...
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于您希望 apache 处理的每个主机,您都需要一个 VirtualHost 条目。如果没有其他 VirtualHost 与请求匹配,则配置文件中的第一个将用作默认值。
例如,如果我们有:
对 foobar.org 的请求将由gift.loc 虚拟主机处理。
You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.
For example if we have:
A request for foobar.org will get handled by the gift.loc virtual host.
你需要将 localhost 放入 vhosts.conf
这工作正常(确保重新启动 apache)。如果您需要检查您的配置,您可以(至少在 Linux 上)运行 httpd -S。
you need to put localhost in the vhosts.conf
This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.
在 ubuntu 上设置虚拟主机需要执行以下几个步骤:
假设您的项目文件夹名称是 myProject
第 1 步:将您的文件夹放入 /var/www/html
第 2 步:将项目文件夹的所有权授予 www-data
第 3 步:在可用站点中创建新站点:
在这里您将看到现有的 000 -default.conf 和 default-ssl.conf 。将两个文件的内容复制到一个文件中并替换您的文件夹名称或将此文件复制到名为 myProject.conf 的新文件
包含自签名证书的路径图中还显示了可以轻松下载的 ssl 密钥和 ssl 证书。
步骤 4:将您的项目添加到 apache 配置文件中。
将此行放入文件中:
步骤 5:将您的虚拟服务器名称(在 myProject.conf 中指定)添加到主机文件中。添加该行:
步骤 6:现在全部设置,启用站点,重新启动 apache
只需在浏览器中点击 project.com 。
There are few steps you need to follow to setup the virtual host on ubuntu:
Let say that your project folder name is myProject
Step 1:Place your folder inside /var/www/html
Step 2: Give ownership of project folder to www-data
Step 3:Create new site inside Sites available:
Here you will see existing 000-default.conf and default-ssl.conf .Copy the content of both file into one file and replace your folder name or copy this one into new file named myProject.conf
Include the path of self signed certificate also in this as shown ssl key and ssl certificate that can be downloaded easily.
Step 4:Add your project into apache configuration file.
put this lines in the file:
Step 5:Add your virtual server name (specified in myProject.conf) into host file.add that line:
Step 6:Now all set ,enable site,restart apache
Just hit project.com in your browser.
从 docs 来看,我们需要为您想要服务的每个不同主机创建一个块。
此外,在同一文档中,如果您要将虚拟主机添加到现有 Web 服务器,则还必须为现有主机创建一个块。
From the docs, it looks like we need to create a block for each different host that you would like to serve.
Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.