今天写一下LINUX下的APACHE的配置方法。 APACHE是作为WEB服务器的。它的优点在于用缓存方式来加快网页的搜索速度。 APACHE缺省只支持静态网页 LINUX下有APACHE的RPM包 安装上第一张盘里的httpd-2.0.40-21.i386.rpm 包 1 /etc/httpd/conf.d 放在这里的都是动态网页的配置文件 2 /etc/httpd/conf/httpd.conf 主配置文件 3 /var/log/httpd 日志文件目录。 4 /var/www/html 网页的存放目录 5 /etc/rc.d/init.d 工具文件目录。 6 vi /etc/httpd/conf/httpd.conf Section 1: Global Environment(全局设置) ServerRoot "/etc/httpd" (APACHE安装路径) DirectoryIndex index.html index.html.var (网页首页的第一页) Timeout 300 (超出时间) KeepAlive Off(保持Httpd激活) MaxKeepAliveRequests 100 (保持的连接的人数,改成0就是说没有人数的限制) KeepAliveTimeout 15 (保持激活的超出时间) prefork MPM (预派生模式) worker MPM (工作者模式) Listen 80 (侦听的端口) LoadModule (加载模块)
Section 2: 'Main' server configuration(服务器配置) User apache Group apache (由谁启动APACHE服务器) ServerAdmin root@localhost (网页出错给谁发信通知) ServerName new.host.name:80(设置网站的域名) DocumentRoot "/var/www/html"(网页存放的路径) <Directory /> (目录容器) Options (选项) FollowSymLinks(允许符号连接,允许这个网页以外的地方) AccessFileName .htaccess(访问文件定义名称文件容器) <Files ~ "^\.ht"> 想把所有以 .ht 开头的文件做限制 Order allow,deny 定义访问顺序 先允许,后拒绝 Deny from all 拒绝所有人 </Files>
Section 3: Virtual Hosts (虚拟主机) NameVirtualHost * (虚拟主机工作的IP) ServerAdmin webmaster@dummy-host.example.com (虚拟主机的管理员的邮件地址) DocumentRoot /www/docs/dummy-host.example.com (网页放在那) ServerName dummy-host.example.com (主机名是什么) ErrorLog logs/dummy-host.example.com-error_log(错误日记路径) CustomLog logs/dummy-host.example.com-access_log common(访问日志路径)
1 基于IP的虚拟主机 1 NameVirtualHost * 放开 2 <VirtualHost 192.168.0.12:80> ServerAdmin webmaster@yirehe.com DocumentRoot /web1 ServerName www.yirehe.com ErrorLog logs/www.yirehe.com-error_log CustomLog logs/www.yirehe.com-access_log common </VirtualHost> 3 <VirtualHost 192.168.0.13:80> ServerAdmin webmaster@zuanmou.com DocumentRoot /web2 ServerName www.zuanmou.com ErrorLog logs/www.zuanmou.com-error_log CustomLog logs/www.zuanmou.com-access_log common </VirtualHost> 2 基于端口的虚拟主机 1 NameVirtualHost 192.168.0.12 放开 2 <VirtualHost 192.168.0.12:8080> ServerAdmin webmaster@yirehe.com DocumentRoot /web1 ServerName www.yirehe.com ErrorLog logs/www.yirehe.com-error_log CustomLog logs/www.yirehe.com-access_log common </VirtualHost> 3 <VirtualHost 192.168.0.12:80> ServerAdmin webmaster@zuanmou.com DocumentRoot /web2 ServerName www.zuanmou.com ErrorLog logs/www.zuanmou.com-error_log CustomLog logs/www.zuanmou.com-access_log common </VirtualHost> 3 基于主机头的虚拟主机 1 NameVirtualHost 192.168.0.12:80 放开 2 <VirtualHost 192.168.0.12:80> ServerAdmin webmaster@yirehe.com DocumentRoot /web1 ServerName www.yirehe.com ErrorLog logs/www.yirehe.com-error_log CustomLog logs/www.yirehe.com-access_log common </VirtualHost> 3 <VirtualHost 192.168.0.12:80> ServerAdmin webmaster@zuanmou.com DocumentRoot /web2 ServerName www.zuanmou.com ErrorLog logs/www.zuanmou.com-error_log CustomLog logs/www.zuanmou.com-access_log common </VirtualHost>
4 做虚拟目录的认证
1找到 /Alias
2 Alias /xinwe/ "/usr/web1"
<Directory "/usr/web1"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all AuthName "huiyuan" AuthType Basic AuthUserFile /etc/pass require valid-user tom1 tom2 </Directory>
3 htpasswd -c /etc/pass tom1 4 htpasswd -c /etc/pass tom2 5 chown apache.apache /etc/pass 6 service httpd reload
另一种方式也可以实现做虚拟目录的认证
1 找到 /Alias 2 Alias /xinwe/ "/usr/web1" <Directory "/usr/web1"> AllowOverride AuthConfig </Directory> 3 然后在/usr/web1文件夹下touch .htaccess 文本文件 4 vi /usr/web1/.htaccess 在里面写入 Options Indexes MultiViews Order allow,deny Allow from all AuthName "huiyuan" AuthType Basic AuthUserFile /etc/pass require valid-user tom1 tom2 5 chown apache.apache /etc/pass htpasswd -c /etc/pass tom1 htpasswd -c /etc/pass tom2 service httpd reload
APACHE有代理局域网上网的功能 把前面的#去掉 #<IfModule mod_proxy.c> #ProxyRequests On (当等于ON的时候说明打开代理) #<Proxy *> # Order deny,allow (把它改成Order allow,deny,) # Deny from all (把它改成Allow from all) # Allow from .your-domain.com (局域网网段比如:Allow from 192.168.0.0/24) #</Proxy>
#ProxyVia On (让代理支持http)
#CacheRoot "/etc/httpd/proxy" (缓存的路径) #CacheSize 5 (缓存的大小) #CacheGcInterval 4 #CacheMaxExpire 24 (缓存最大的过期时间) #CacheLastModifiedFactor 0.1 #CacheDefaultExpire 1 (最短的过期时间) #NoCache a-domain.com another-domain.edu joes.garage-sale.com (不缓存那些域名) 客户端改IE 依次 工具--Internet选项--连接--局域网设置--勾上为LAN使用使用代理服务器--填写APACHE主机的 IP地址比如:192.168.0.20 端口:80
到这里APACHE的配置讲完了. 希望看完我的配置你可以配置网站的服务器! 本文出自 “E网咖啡猫” 博客,转载请与作者联系! 本文出自 51CTO.COM技术博客 |