linux 查看apache的版本 |
您所在的位置:网站首页 › 三菱系统怎么看版本号 › linux 查看apache的版本 |
一、基本介绍 1、版本 httpd-1.3 httpd-2.0 httpd-2.2 httpd-2.4 目前为止最新的版本是httpd-2.4.6,但是这里我用的是系统自带的RPM包安装的httpd-2.2.15版本的,最新版本配置可能会有所不同 2、模型: 高度模块化:DSO MPM:Multipath Processing Module #多处理模块 prefork:一次一个进程响应一个请求 worker:一个进程生成多个线程,一个线程响应一个请求 event:基于事件驱动,一个进程响应多个请求 3、安装 这里就直接rpm包安装了,光盘上就有软件包 yum install httpd 4、httpd安装完后的基本信息 服务脚本:/etc/rc.d/init.d/httpd 运行目录:/etc/httpd/ 配置文件:/etc/httpd/conf 主配置文件:/etc/httpd/conf/httpd.conf 扩展配置:/etc/httpd/conf.d/*.conf socket:http:80/tcp,https:443/tcp 网页文件目录(DocumentRoot):/var/www/html CGI:/var/www/cgi-bin/ 默认主页面文件:/var/www/html/index.html 5、主配置文件结构 全局配置:对主服务器或虚拟主机都有效,且有些功能是服务器自身工作属性; 主服务器配置:主站属性 虚拟服务器:虚拟主机及属性定义 6、测试配置和查看的命令 所使用的 service httpd configtest #测试配置文件有没有语法错误 httpd -t #同上 httpd -l #当前服务器所使用的模型及开启模块 httpd -D DUMP_MODULES #当前服务器支持的模块 service httpd reload #重新加载配置文件 service httpd restart #重启httpd服务 注意:修改配置文件后要重新加载配置文件,修改服务器监听端口后要重启服务 二、基本配置 温馨提示:配置httpd的工作属性时,指令不区分大小写,但有约定俗成的习惯:单词的首字母大写;指令的值很有可能区分大小写;有些指令可以重复使用多次; 1、配置监听的端口: Listen [IP:]PORT 例如:Listen 172.16.3.1:80 注意:省略Ip表示监听本机所有ip,Listen可重复出现多次。 2、配置所选用的MPM的属性 编译安装:httpd-2.2不支持同时编译多个模块,所以只能编译时选定一个; rpm安装:rpm安装的包提供三个二进程程序文件,分别用于实现对不同的mpm机制的支持,安装完默认使用prefork模型; 确认方法: # ps aux | grep httpd 默认为/usr/sbin/httpd,其使用prefork模型 StartServers 8 #服务启动后默认开启的进程数 MinSpareServers 5 #最少空闲进程数 MaxSpareServers 20 #最多空闲进程数 ServerLimit 256 #每个进程允许开启最多的子进程数 MaxClients 256 #每个进程最多用户链接数 MaxRequestsPerChild 4000 #长连接时每个用户最多请求数 worker模型:要支持worker模型需要配置/etc/sysconfig/httpd,开启以下行: HTTPD=/usr/sbin/httpd.worker StartServers 4 #服务启动默认开启的进程数 MaxClients 300 #最多同时客户连接数 MinSpareThreads 25 #最少空闲进程数 MaxSpareThreads 75 #最好空闲进程数 ThreadsPerChild 25 #每个进程开启的线程数 MaxRequestsPerChild 0 3、配置服务器支持keep-alived(长连接) KeepAlive {On|Off} #是否支持长连接 KeepAliveTimeout 2 #长连接超时时间 MaxKeepAliveRequests 50 #超时时间内允许请求的次数 测试: telnet HOST PORT GET /URL HTTP/1.1 Host:HOSTNQME or IP 4、配置加载模块 # LoadModule foo_module modules/mod_foo.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so 5、配置网站根目录 DocumentRoot "/var/www/html" #指定网站的主目录 #容器内定义站点的访问权限 #容器内限定用户的访问方法 6、配置页面文件的访问属性 Options Indexes #是否允许索引页面文件,建议关闭 FollowSymLinks #是否跟随软连接文件 SymLinksifOwnerMatch #跟随符号链接,只允许访问运行apache的用户有属主权限的文件 ExecCGI: #是否允许执行CGI脚本; All None 7、基于客户端访问控制 系统默认允许所有人访问 Order #定义allow和deny那个为默认法则;写在后面的为默认法则:写在前面的指令没有显示定义的即受后面的指令控制: Order allow,deny Allow from all #所有人可以访问 配置允许172.16.0.0/16访问,但不允许172.16.3.1访问 Order allow,deny Deny from 172.16.3.1 #禁用一个IP访问 Allow from 172.16.0.0/16 #允许一个网段访问 8、userdir个人站点
# UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # #UserDir disabled #注释此项 # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # UserDir public_html #开启此项 重新加载配置文件后用:http://HOST/~username/ 例如:http://172.16.3.1/~centos/ 9、定义默认主页 1DirectoryIndex index.php index.jsp index.html 10、配置日志功能 日志有两类:访问日志(格式自定义)、错误日志 错误日志: ErrorLog "/path/to/error_log_file" 访问日志: CustomLog "/path/to/custom_log_file" logformat 日志格式:{combined|common|agent} LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent %h #主机名 %l # %u #用户名 %t #请求到达的时间 %r #请求报文的起始行,方法 %s # %b #响应报文的大小 %{Foobar}i #显示从发那个站点跳转过来 %{User-Agent}i #用户代理 11、支持的字符集 1AddDefaultCharset UTF-8 12、路径别名 可以隐藏网站的真实目录, Alias /test/ "/www/test/" #配置别名 #可以给别名目录定义访问权限 Options None AllowOverride None Order allow,deny Allow from 172.16.0.0/16 13、脚本路径别名 调用服务器上的脚本程序,但不希望脚本放在网站的目录下 ScriptAlias /cgi-bin/ "/www/cgi-bin/" #定义cgi脚本路径别名 # vi /wwww/cgi-bin/test.sh #写一个测试脚本 #!/bin/bash #cat /www/web1/index.html echo web2.lyd.com > /www/web2/index.html (3)配置完后用 httpd -t 测试配置文件有没有错误 (4)重启服务 service httpd restart (5)验证,修改验证客户端的hosts文件, windows客户端 开始-->运行-->输入"c:\windows\system32\drivers\etc\hosts"用记事本打开并添加以下行 172.16.3.1web1.lyd.com 172.16.3.1web2.lyd.com 16、配置支持https (1)安装httpd支持ssl模块 yum install mod_ssl -y (2)自建CA #cd /etc/pki/CA # (umask 077; openssl genrsa -out private/cakey.pem 2048) #openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365 (3)生成私钥 cd /etc/httpd/conf/ mkdir ssl cd ssl (umask 077; openssl genrsa -out httpd.key 1024) (4)生成证书申请 1openssl req -new -key httpd.key -out httpd.csr (5)ca签署证书 1openssl ca -in httpd.csr -out httpd.crt -days 365 (6)修改httpd的ssl配置文件 vi /etc/httpd/conf.d/ssl.conf DocumentRoot "/www/web1" ServerName www.lyd.com SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key (7)将ca证书导入到客户端可信任证书服务器,并验证 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |