【问题标题】:Apache2, creating virtual hosts on one ip addressApache2,在一个 IP 地址上创建虚拟主机
【发布时间】:2017-08-13 03:43:39
【问题描述】:

我没有命名这个的术语,但基本上我一直在尝试做的是在没有任何专用 dns 的情况下从我的 IP 地址运行不同的 Web 开发项目。 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>

【问题讨论】:

    标签: ubuntu apache2


    【解决方案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

    根据您的编辑,您可以这样尝试,请记下 cmets:

    <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>
    

    【讨论】:

    • 好点卡拉姆。但很可惜,我没有取得任何成功。我尝试了我认为您的意思,正如您在我刚刚在上面发布的 .conf 文件中看到的那样。我仍然收到 404 错误。我希望 .conf 文件能让问题更容易理解。
    猜你喜欢
    • 2021-10-26
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 2018-07-25
    • 2012-07-28
    • 1970-01-01
    • 2012-03-18
    相关资源
    最近更新 更多