gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:13:49 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com