Apache2,在一个ip地址上创建虚拟主机

时间:2017-08-13 03:43:40

标签: ubuntu apache2

我没有这个术语来说明这一点,但基本上我一直试图做的是从我的IP地址运行不同的web开发项目而没有任何专用的dns' s。 IE浏览器。我可以从11.11.11.11/site1,11.11.11.11/site2和11.11.11.11/site3访问不同的站点。

现在我一直认为能够做到但我无法做到。我每次都得到错误404。

我已经在网站中设置了我的.conf文件,因此服务器名称是' 11.11.11.11/site#'和每个主机的DocumentRoot到/var/www/html/example.com/public_html。仍然没有运气。

有谁知道会出现什么问题?

这是我的一个.conf文件的例子,它给了我404错误:

<VirtualHost *:80>
        ServerName ###.###.###.###/example.html
        #the hashes represent my actual ip.

        ServerAdmin webmaster@localhost
        Alias /example.html /index.html
        DocumentRoot /var/www/html/example.com/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

您必须使用别名:

Alias /site1 /home/site1/
Alias /site2 /home/site2/
Alias /site3 /home/site3/
# Don't add trailing slash at the end of the alias address ie. /site1/ is wrong . 

more inforamtion

根据您的修改,您可以尝试这样做,请注意下面的评论:

<VirtualHost *:80>
        ServerName 127.0.0.1
        #don't put any file name just dns name so you may use localhost 
        #or your domain.com or an IP.
        ServerAdmin webmaster@localhost
        Alias /site1 /var/www/html/folder/to/site1
        Alias /site2 /var/www/html/folder/to/site2

         #you will assign an alias folder name to real folder in your system 
         #so the first argument is /site1 and it can be anything you want 
         #you can make it /app and make it point to /path/to/site/2
         #You don't need to specify file names like you did in your example           
         #you just put the folder name and inside that folder you can access any file 
         #defult to index.html

        DocumentRoot /var/www/html/example.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>