且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Linux上使用Apache设置子域

更新时间:2023-09-01 11:38:16

您正在

You are telling Apache what IP and port you want to answer it on inside of the <VirtualHost> tag so here * means any IP, but accept requests for this site on port 80. Next you need to tell Apache where the document root is. ~/ means your default home directory, so if your DocumentRoot just happens to be the default home variable then it would work with your existing notation (depending on which user you're running the server as). Then you would declare the server name.

您要为其创建主机的每个域名都需要自己的虚拟主机指令,除非您使用别名.

Each domain name you're create a host for needs its own Virtual Host Directive unless you're using aliases.

<VirtualHost *:80>
    DocumentRoot /home/sam/public_html
    ServerName myproject.localhost

    # Other directives here

</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/sam/public_html/myproject
    ServerName myotherproject.localhost

    # Other directives here

</VirtualHost>

关于主机 除此之外,您为主机创建的任何特殊名称都需要进入主机文件或DNS服务器中.这样,任何正在寻找您的服务器的Web浏览器都可以找到它,而无需键入IP.如果您尝试仅使用IP访问服务器,则可能会在设置中将多个主机置于同一IP上,因此,您只会获得第一个响应IP的主机(通常是vhosts列表中的顶部)

About Hosts In addition to this, any special name that you create for a host needs to go into a hosts file or in the DNS server as well. This way any web browser that is looking for your server can find it without having to type in the IP. Since you'll likely have multiple hosts on the same IP with your setup if you were to try and access the server with the IP only, you would only get the first host to respond on the IP (usually the top in the vhosts list).