我感兴趣的是,如果我可以在 apache 上使用域名如下的虚拟主机: http://something.com/something或http://{server-ip-address-here}/something?
我在 Ubuntu Server 上使用 Apache 2.2.20,那是我的家庭服务器,我在这里测试一些东西,我这里没有任何 DNS 服务器,我只有公共 IP 地址和一个从开放 dns 服务附加到它的域名.
那么,我做了什么:
- 我在/etc/apache2/sites-available中创建了新文件“demo”
我把它放在那里(实际上它是通过默认文件的修改复制的):
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName {mydomain-here}/demo/ DocumentRoot /vhosts/demo <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /vhosts/demo/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
在 /etc/apache2/sites-enabled/ 中创建了指向 /etc/apache2/sites-available/demo 的符号链接
创建/vhosts/demo/index.html文件。
现在我得到的是,当我转到 {my-domain} 时,我转到了我创建的虚拟主机,但问题是服务器在任何情况下都将我指向那里,而不仅仅是 {my-domain}/demo 我想要的。
总之,我希望我可以创建不同的虚拟主机并将它们附加到具有相同基本 URL 的不同 URL,例如 www.mydomain.com/vhost1、www.mydomain.com/vhost2 等。
是否可以?谢谢 :)