如何在专用的 apache2 服务器中创建子域 [英] how to create a subdomain in a dedicated apache2 server

查看:35
本文介绍了如何在专用的 apache2 服务器中创建子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照以下步骤创建一个子域:

I want to create a subdomain I followed this steps :

cd /etc/apache2/sites-available
nano test.mydomaine.com

<VirtualHost *:80>
        ServerAdmin mymail@gmail.com
        ServerName  test.mydomaine.com
        ServerAlias www.test.mydomaine.com
        DocumentRoot /var/www/testfolder/
<Directory "/var/www/testfolder">
        AuthType Basic
        AuthName "test"
        AuthUserFile /var/www/testfolder/passwords
        Require valid-user test
</Directory>
</VirtualHost>

退出并保存

a2ensite test.mydomaine.com
/etc/init.d/apache2 reload

但是它不起作用是我遗漏了什么吗?

but It's not working am I missing something ?

推荐答案

为了使其正常工作,您还必须为新主机名 test.mydomain.com 配置 DNS 解析.如果您只是在本地玩这个并且不想创建真正的"DNS 条目,您必须编辑文件 /etc/hosts 以便您的计算机可以将主机名解析为 IP 地址.如果您在与浏览器相同的机器上运行 Web 服务器,您需要将 test.mydomain.com 映射到 127.0.0.1.如果浏览器在本地网络上的另一台机器上,您需要确定服务器的 IP 地址,然后在 浏览器 机器上,将 /etc/hosts 编辑为添加映射.

In order for this to work, you additionally have to configure DNS resolution for the new hostname test.mydomain.com. If you are just playing with this locally and do not want to create a "real" DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1. If the browser is on a different machine on your local network, you'll need to determine the server's IP address and then on the browser machine, edit /etc/hosts to add the mapping.

在 Windows 上,该文件名为 C:\windows\system32\drivers\etc\hosts

On Windows, the file is called C:\windows\system32\drivers\etc\hosts

示例条目将是(对于与服务器在同一台机器上运行的浏览器):

A sample entry would be (for the browser running on the same machine as the server):

127.0.0.1 test.mydomain.com

如果服务器在,比如 192.168.0.5,条目将是

If the server is at, say 192.168.0.5, the entry would be

192.168.0.5 test.mydomain.com

如果服务器有一个真正的可路由 IP 地址,那么如果您希望 test.mydomain.com 地址在全球互联网上解析,您将必须让您的服务提供商添加它到 DNS.出于测试目的,您仍然可以使用 /etc/hosts 如上所述.只需替换服务器的真实 IP 而不是 127.0.0.1.在您运行浏览器的系统上执行此操作.

If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server's real IP instead of 127.0.0.1. Do this on the system where you are running the browser.

这篇关于如何在专用的 apache2 服务器中创建子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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