我想在我的电脑上用XAMPP for Linux运行两个网站:
他们是完全不相关的,我不希望一个在另一个的子域上运行,我不想搞乱.htaccess文件。
最好的办法是什么?
只要设置你的虚拟主机是这样的:
Name VirtualHost 127.0.0.1 <VirtualHost *:80> DocumentRoot /www/thesis ServerName thesiswork </VirtualHost> <VirtualHost test2:80> DocumentRoot /www/test2 ServerName test2 </VirtualHost> <VirtualHost test3:80> DocumentRoot /www/test3 ServerName test3 </VirtualHost>
然后在/ etc / hosts文件中执行以下操作:
example.com 127.0.0.1 test2.example.com 127.0.0.1 test2.example.com 127.0.0.1 test2 127.0.0.1 test3 127.0.0.1
这样,你可以去:example.com或test3.example.com(在你改变主机的configuration后,确保你重新启动networking。
我推荐一个基于端口的vhosts.conf像这样(这是完整的vhosts.conf):
NameVirtualHost *:80 <virtualHost *:80> DocumentRoot "/var/www/" ServerName localhost ServerAdmin admin@localhost </VirtualHost> Listen 61 #use random free port number <virtualHost *:61> DocumentRoot "/var/vhosts/thesis/" ServerName asdf ServerAdmin admin@asdf </VirtualHost>
然后,您可以使用http:// localhost /和您的论文东西用http:// localhost:61 /
基于端口的基于名称的虚拟主机的优点是,你不需要一个域,你不需要弄乱你的主机文件,我发现这是一种“脏”的东西。
确保你允许访问你希望将你的论文文件放入的目录,例如在你的httpd.conf文件中,或者把它添加到你的vhosts.conf中:
<Directory "/var/vhosts/"> Order Deny,Allow Allow From All AllowOverride All </Directory>
127.0.0.0/8表示127.0.0.2和127.0.0.3和127.0.0.4和…高达127.254.254.254或类似的东西是可用的IP地址使用。 所以如果基于名字的虚拟主机不够好,你可以为每个网站有不同的本地主机,比如IP地址。
您应该使用基于名称的虚拟主机。 详细信息在这里列出: http : //httpd.apache.org/docs/current/vhosts/name-based.html
基本的想法是,你将在localhost上设置一个默认的虚拟主机,像这样:
<VirtualHost _default_:*> DocumentRoot /www/default </VirtualHost>
那么,对于你的论文网站,你可以设置另一个虚拟主机
<VirtualHost *:80> DocumentRoot /www/thesis ServerName thesiswork </VirtualHost>
在你的本地计算机上,你将不得不编辑你的/ etc / hosts文件来包含“文章”,指向127.0.0.1