如何设置 2 个具有相同根地址的虚拟主机?
how to set up 2 virtualhosts with the same root adress?
我想在同一个 IP 地址上设置 2 个 wordpress 站点,即 ip_adress1/wordpress1
和 ip_adress1/wordpress2
。
我把这2个文件放到了/etc/apache2/sites-available中(基本上是一样的,只是网站的路径变了)
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress/MyFirstSite/
ServerName my.ip.adr.ess
ServerAlias my.ip.adr.ess/MyFirstSite/*
ServerAdmin myemail@adress.ext
Alias /MyFirstSite /usr/share/wordpress/FolderForMyFirstSite
<Directory /usr/share/wordpress/FolderForMyFirstSite>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/FolderForMyFirstSite/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
和
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress/MySecondSite/
ServerName my.ip.adr.ess
ServerAlias my.ip.adr.ess/MySecondSite/*
ServerAdmin myemail@adress.ext
Alias /MyFirstSite /usr/share/wordpress/FolderForMySecondSite
<Directory /usr/share/wordpress/FolderForMySecondSite>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/FolderForMySecondSite/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
当我启用它们时,sites-available 中的 2 个站点似乎可以单独工作。
当我同时启用它们时,只有一个有效。我认为它正在覆盖另一个...(顺便说一下,没有 apache 错误)
还有一件事:当我到达 http://my.ip.adr.ess
时,网站可以正常工作(没有网站的路径)。而且我不想这样!
你怎么看?
非常感谢
斯坦尼斯拉斯
我终于做了这个,在阅读了更多关于 apache 配置的文档 (https://httpd.apache.org/docs/2.2/mod/mod_alias.html) 之后看起来更好了:
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress
ServerName my.ip.adr.ess
ServerAdmin my.email@adress.ext
Alias /Alias1 /usr/share/wordpress/Folder1
<Directory /usr/share/wordpress/Folder1>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/Folder1/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
Alias /Alias2 /usr/share/wordpress/Folder2
<Directory /usr/share/wordpress/Folder2>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/Folder2/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
我想在同一个 IP 地址上设置 2 个 wordpress 站点,即 ip_adress1/wordpress1
和 ip_adress1/wordpress2
。
我把这2个文件放到了/etc/apache2/sites-available中(基本上是一样的,只是网站的路径变了)
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress/MyFirstSite/
ServerName my.ip.adr.ess
ServerAlias my.ip.adr.ess/MyFirstSite/*
ServerAdmin myemail@adress.ext
Alias /MyFirstSite /usr/share/wordpress/FolderForMyFirstSite
<Directory /usr/share/wordpress/FolderForMyFirstSite>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/FolderForMyFirstSite/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
和
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress/MySecondSite/
ServerName my.ip.adr.ess
ServerAlias my.ip.adr.ess/MySecondSite/*
ServerAdmin myemail@adress.ext
Alias /MyFirstSite /usr/share/wordpress/FolderForMySecondSite
<Directory /usr/share/wordpress/FolderForMySecondSite>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/FolderForMySecondSite/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
当我启用它们时,sites-available 中的 2 个站点似乎可以单独工作。
当我同时启用它们时,只有一个有效。我认为它正在覆盖另一个...(顺便说一下,没有 apache 错误)
还有一件事:当我到达 http://my.ip.adr.ess
时,网站可以正常工作(没有网站的路径)。而且我不想这样!
你怎么看?
非常感谢
斯坦尼斯拉斯
我终于做了这个,在阅读了更多关于 apache 配置的文档 (https://httpd.apache.org/docs/2.2/mod/mod_alias.html) 之后看起来更好了:
<VirtualHost *:80>
DocumentRoot /usr/share/wordpress
ServerName my.ip.adr.ess
ServerAdmin my.email@adress.ext
Alias /Alias1 /usr/share/wordpress/Folder1
<Directory /usr/share/wordpress/Folder1>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/Folder1/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
Alias /Alias2 /usr/share/wordpress/Folder2
<Directory /usr/share/wordpress/Folder2>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
<Directory /usr/share/wordpress/Folder2/wp-content>
Options FollowSymLinks MultiViews
Order allow,deny
AllowOverride All
Allow from all
</Directory>
</VirtualHost>