ubuntu - Apache2,在一个 IP 地址上创建虚拟主机

标签 ubuntu apache2

我没有命名这个的术语,但基本上我一直在尝试做的是在没有任何专用 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>

最佳答案

您必须使用别名:

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>

关于ubuntu - Apache2,在一个 IP 地址上创建虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45656861/

相关文章:

php - 编写apache环境变量并在php脚本中读取它们

ubuntu - 如何安装特定版本的钢筋?

android - 无法在 ubuntu 上的 android studio 1.4 中解析 : junit:junit:4. 12

django - 在 apache2 服务器上运行的 django 站点的 'correct' 权限设置是什么

Apache2反向代理到需要BasicAuth但希望对用户隐藏的端点

php - 仅将一页从安全 https 重定向到 http

c++ - 无法使用带有boost C++的ubuntu中的完整路径打开文件

linux - Ubuntu:找不到 hadoop 命令

linux - 使用 Apache2 记录特定错误

.htaccess - CakePHP 和 VirtualDocumentRoot 问题