以下是服务器配置文件(Server configuration)httpd.conf中需要添加的信息 # Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/deerol_com ServerName www.deerol.com # Other directives here #配置域名的目录访问权限 <Directory '/www/deerol_com'> Options Indexes FollowSymLinks allow from all </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot /www/163_com ServerName www.163.com # Other directives here #配置域名的目录访问权限 <Directory '/www/deerol_com'> Options Indexes FollowSymLinks allow from all </Directory> </VirtualHost> ·以上代码应该加入到Apache配置文件httpd.conf中的类似代码的后面; ·DocumentRoot表示网站根目录,ServerName表示需要服务的域名,80表示Apache监听80端口 在你正确写入以上代码之后,apache会就用户访问的域名对应配置中的ServerName选择合适的web目录输出html代码。以上设置中第一项(即
在配置时可能遇到的场景: 1.使用域名加端口访问 如果需要带端口访问(这种情况很少,一般会在测试时用到)如:www.domain.com:8081 这时在配置<VirtaulHost> 后,还需要添加对该端口的监听Listen 8081 2.如果服务器上除了Apache服务外还装了IIS(运行asp,asp.net程序),Tomcat(运行java,jsp程序)服务该如何配置? 一般的我们会把Apache默认为80端口,IIS可以设置为81端口,Tomcat设置为8080端口。假设有一jsp程序,在服务器本地配置时我们可以通过http://localhost:8080/document访问。那如何配置通过域名访问到该地址呢? <VirtualHost *:80> ProxyPreserveHost On ServerName yourdomain.com DirectoryIndex index.jsp ProxyPass / http://localhost:8080/KBoom/ ProxyPassReverse / http://localhost:8080/KBoom/ </VirtualHost>这里我们注意到使用了代理访问。首先开启代理支持ProxyPreserveHost On,然后再配置正向代理和反向代理 ProxyPass / http://localhost:8080/KBoom (kboom为虚拟目录) |
|