Apache虚拟主机不适用于我的两个域

发布于 2025-01-25 10:14:33 字数 2778 浏览 4 评论 0 原文

VirtualBox上的Ubuntu Server 20.04。每当我访问网站2时,我都可以从Windows主机上的Web浏览器中访问网站1的内容,它将我重定向到网站1,但将网站2显示为域名。我已经编辑了Windows Hosts文件,以将witch worket1和weblity2映射到VM的本地IP:

我安装了Apache2,创建了目录并给出了权限:

sudo mkdir -p /var/www/website1/public_html
sudo mkdir -p /var/www/website2/public_html

sudo chown -R $USER:$USER /var/www/website1/public_html
sudo chown -R $USER:$USER /var/www/website2/public_html

sudo chmod -R 755 /var/www

index.html每个网站的内容不同:

/var/www/website1/public_html/index.html
/var/www/website2/public_html/index.html

我已经为每个域都具有以下配置:

网站1:

/etc/apache2/sites-available/website1.conf: 

<VirtualHost *:80>
  ...
    ServerAdmin [email protected]
    ServerName www.website1.com
    ServerAlias www.website1.com
    DocumentRoot /var/www/website1.com/public_html
    ...
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ...
</VirtualHost>

网站2:

/etc/apache2/sites-available/website2.conf:  

<VirtualHost *:80>
      ...
        ServerAdmin [email protected]
        ServerName www.website2.com
        ServerAlias www.website2.com
        DocumentRoot /var/www/website2.com/public_html
        ...
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ...
    </VirtualHost>

i启用和禁用默认的apache网站:

sudo a2ensite website1.conf
sudo a2ensite website2.conf
sudo a2dissite 000-default.conf

我遵循本指南的数字海洋指南,以及多个没有运气的其他人。

我还尝试在COND中添加一个目录块.conf and werfeent2.conf:

网站1:

/etc/apache2/sites-available/website1.conf: 

<Directory /var/www/website1.com/public_html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
</Directory>

网站2:

/etc/apache2/sites-available/website2.conf: 
            
<Directory /var/www/website2.com/public_html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
 </Directory>

非常笨拙,遵循多个指南和官方Apache文档,这应该正确,但我肯定会缺少一些东西。猜测这与分辨率有关。

似乎唯一起作用的是基于端口的虚拟主机,因此我将网站1配置为默认端口80和weblity2为8081等。尽管我想要网站2(如果我想要网站2)必须手动端口8081。

Ubuntu Server 20.04 on VirtualBox. I can access only the content of website1 from my web browser on a windows host, whenever I visit website 2 it redirects me to website1 but shows website2 as the domain name. I have edited my windows hosts file to map website1 and website2 to the local IP of the VM:

I installed Apache2, created the directories and gave permissions:

sudo mkdir -p /var/www/website1/public_html
sudo mkdir -p /var/www/website2/public_html

sudo chown -R $USER:$USER /var/www/website1/public_html
sudo chown -R $USER:$USER /var/www/website2/public_html

sudo chmod -R 755 /var/www

Index.html with different content for each website:

/var/www/website1/public_html/index.html
/var/www/website2/public_html/index.html

I've created the two conf files for each domain with the following configuration:

Website1:

/etc/apache2/sites-available/website1.conf: 

<VirtualHost *:80>
  ...
    ServerAdmin [email protected]
    ServerName www.website1.com
    ServerAlias www.website1.com
    DocumentRoot /var/www/website1.com/public_html
    ...
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ...
</VirtualHost>

Website2:

/etc/apache2/sites-available/website2.conf:  

<VirtualHost *:80>
      ...
        ServerAdmin [email protected]
        ServerName www.website2.com
        ServerAlias www.website2.com
        DocumentRoot /var/www/website2.com/public_html
        ...
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ...
    </VirtualHost>

I enabled and disabled default apache site:

sudo a2ensite website1.conf
sudo a2ensite website2.conf
sudo a2dissite 000-default.conf

I followed this guide on digital ocean, as well as multiple others with no luck.
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04

I also tried adding a Directory block within the conf to both website1.conf and website2.conf:

Website1:

/etc/apache2/sites-available/website1.conf: 

<Directory /var/www/website1.com/public_html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
</Directory>

Website2:

/etc/apache2/sites-available/website2.conf: 
            
<Directory /var/www/website2.com/public_html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
 </Directory>

Pretty stumped, following multiple guides and official Apache documentation this should work right but surely I am missing something. Guessing it's resolution related.

The only thing that seems to work is port based virtual hosts, so I configured website1 as default port 80 and website2 as 8081 etc. Unpractical though because I had to manual type port 8081 if I wanted website2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文