一、虚拟目录
现场模拟:
本来的访问路径为:localhost/demo/demo1
想把访问路径改为:localhost:701/demo1
1、找到sites-available目录
cd /etc/apache2/sites-available
2、创建一个文档demo,把default文档的内容拷贝过去
default文档内容如下(需要修改的地方用红色标记):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
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>
3、修改
<VirtualHost *:80>改为<VirtualHost *:701>
DocumentRoot /var/www修改成DocumentRoot
/var/www/demo
<Directory
/var/www/>修改成<Directory /var/www/demo>
4、链接到sites-enabled
sudo ln -s /etc/apache2/sites-available/demo /etc/apache2/sites-enabled/demo
5、修改端口监听文件
打开/etc/apache2的ports.conf,找到NameVirtualHost *:80,在下行添加Listen 701,即
NameVirtualHost *:80
Listen 80
Listen 701
6、重启apache2, sudo apachectl restart
ok。
二、设置虚拟域名
现场模拟:将localhost改成www.dxw.com
1、打开/etc/的hosts文件
2、在文档上面相应位置加上一行
127.0.0.1 www.dxw.com
ok。
Ubuntu升级后Apache虚拟目录设置全部失效问题解决:http://www.linuxdiyf.com/linux/10426.html
Linux搭建中文域名的DNS服务器:http://www.linuxdiyf.com/linux/10766.html