Linux下的apache服务
操作系统:Redhat5.8软件安装:
#yum install httpd
软件启动:
#/etc/init.d/httpd start
#chkconfig httpd on
修改配置:
1. 配置文件所在目录分类
#cd /etc/httpd/ -->apache的根目录
#cd /etc/httpd/logs -->日志目录
#cd /etc/httpd/modules -->模块目录
#cd /etc/conf.d
#cd /etc/conf
2.httpd配置文件
#vim /etc/httpd/conf/httpd.conf
一共分3部分:
全局;局部;虚拟主机
ServerRoot "/etc/httpd" -->apache根目录
/var/lib/run/ -->pid文件位置
Timeout 120
KeepAlive Off
MaxKeepAliveRequests
KeepAliveTimeout
StartServers8
MinSpareServers5
MaxSpareServers20
ServerLimit256
MaxClients256
MaxRequestsPerChild4000
StartServers2
MaxClients150
MinSpareThreads25
MaxSpareThreads75
ThreadsPerChild25
MaxRequestsPerChild0
Listen 80
LoadModule auth_basic_module modules/mod_auth_basic.so -->支持的模块
...
LoadModule version_module modules/mod_version.so
Include conf.d/*.conf
DocumentRoot "/var/www/html" -->网站根目录
DirectoryIndexindex.html index.html.var -->首页支持的类型
ServerAlias
2.1 进程与线程的区别
进程相对稳定;独占内存,较快
线程并发量高;共享内存,相对较慢
进程、线程切换
#vim /etc/sysconfig/httpd
注释掉该行:#HTTPD=/usr/sbin/httpd.worke r -->默认进程
默认开启8个子进程
HTTPD=/usr/sbin/httpd.worker -->切换为线程
默认开启2个子进程
可用ps命令查看
ex:
#ps -ef | grep http
or
#ps -aux | grep http
3. 个人主页
ex:
#useradd user100
#chmod a+x /home/user100
#mkdir /home/user100/public_html -->个人主页在家目录~/public_html
#vim /etc/httpd/conf/httpd.conf
将UserDir disable注释掉 --> #UserDir disable
将UserDir public_html的注释去掉
查看测试:
http://IP/~user100/
4. 用户认证
AllowOverride All -->在要认证的用户配置下添加
ex:
#vim /etc/httpd/conf/httpd.conf
AllowOverride All
htpasswd -c /home/user100/public_html/.htpasswd test100
-->文件名可任取,建议以.ht为开头
-->test100为认证用户名,回车设置认证密码
#vim /home/user100/public_html/.htaccess -->该文件名.htaccess固定
authname "..."
authtype basic
authuserfile "/home/user100/public_html/.htpasswd"
-->需和上面的文件名.htpasswd对应
require valid-user
5. 虚拟主机
5.1 基于域名
在现有的web服务器上增加虚拟主机,必须也为现存的主机建造一个定义
块,该虚拟主机中的ServerName和DocumentRoot所包含的内容应该与全局的ServerName和
DocumentRoot保持一致,且要把这个虚拟主机放在配置文件的最前面扮演默认主机的角色
ex:
#vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
ServerName www.uplooking.com
DocumentRoot /www/uplooking
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
6. url地址重写
ex:
Alias /user100 "/home/user100/public_html"
Order allow,deny--> 先Deny后Allow
Allow from all
Deny form 192.168.1.70
服务重启与重载:
#/etc/init.d/httpd restart -->重启
#/etc/init.d/httpd reload -->重载
页:
[1]