安装软件包httpd(软件包)httpd-devel(开发工具)httpd-manual(服务手册)
[root@localhostyum.repos.d]# yum install httpd httpd-devel httpd-manual –y
启动服务
[root@localhost~]# service httpd restart 停止 httpd: [失败] 启动 httpd: [确定]
默认端口 TCP 80
查看服务进程,是否成功启动
[root@localhost~]# netstat -ln | grep :80 tcp 0 0 :::80 :::* LISTEN
查看所有httpd进程,一个父进程,其余均为此进程的子进程。pstree –p 可以查看
[root@localhost~]# ps -ef | grep http root 4959 1 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4960 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4961 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4962 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4963 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4964 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4965 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4967 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd apache 4968 4959 0 10:10 ? 00:00:00 /usr/sbin/httpd
enlinks,命令行浏览器命令。--dump以文本方式显示,--source以源码方式显示,-default-keys使用用户名密码登陆。
[root@localhost~]# elinks --dump /var/www/error/noindex.html [root@localhost~]# elinks --dump http://www.example.com [root@localhost~]# elinks -default-keys http://www.example.com/movie
编辑主配置文件。
[root@localhost ~]#vim /etc/httpd/conf/httpd.conf 265 #ServerName //本站点的FQDN名称 281 DocumentRoot"/var/www/html" //网页文档的根目录 391 DirectoryIndex index.html index.html.var //默认首页文件 472 ErrorLog logs/error_log //错误日志文件位置 501 #CustomLog logs/access_log common //访问文件位置 134 Listen 80 //监听端口 63 PidFile run/httpd.pid //进程文件位置 57 ServerRoot "/etc/httpd" //服务目录 251 ServerAdmin root@localhost //管理员邮箱 231 User apache //服务所属用户 232 Group apache //服务所属组 68 Timeout 120 //网络连接超时 74 KeepAlive Off //是否保持连接 81 MaxKeepAliveRequests 100 //每次连接最多处理的请求数 87 KeepAliveTimeout 15 //保持连接的超时时限 210 Include conf.d/*.conf //可以包含其他子配置文件
网页文档的根目录
[root@localhost~]# cd /var/www/html/ [root@localhosthtml]# ls Authdir 编辑主页内容 [root@localhosthtml]# vim index.html
客户机地址限制
root@localhost~]# vim /etc/httpd/conf/httpd.conf Order deny,allow 先拒绝后允许,默认允许所有 Allow from all Allow,deny先允许后拒绝,默认拒绝所有。 先读前边限制,继续读后一限制,若冲突,以后一限制为准。若要限制某一IP则为 order allow,deny deny IP地址
对目录进行用户限制
[root@localhost~]# mkdir /var/www/html/authdir/ [root@localhost~]# vim /var/www/html/authdir/index.html <h1>TEST</h1>
添加一访问用户并设密码,-c 路径表示新建一用户文件。
[root@localhost~]# htpasswd -c /etc/httpd/auth.ulist admin Newpassword: Re-typenew password: Addingpassword for user admin
编辑主配置文件,添加目录访问控制
[root@localhost~]# vim /etc/httpd/conf/httpd.conf <Directory"/var/www/html/authdir/"> Authname "Need Auth" 认证领域名称 Authtype basic 认证类型 Authuserfile /etc/httpd/auth.ulist 用户数据文件的路径 Require valid-user指定用户或组的授权 </Directory> [root@localhost~]# service httpd restart 停止 httpd: [确定] 启动 httpd: [确定]
访问路径别名设置
[root@localhostly]# mkdir -p /var/www/html/l/y/z/c/t [root@localhostly]# vim /var/www/html/l/y/z/c/t/index.html [root@localhostly]# vim /etc/httpd/conf/httpd.conf Alias/123 "/var/www/html/l/y/z/c/t" [root@localhostly]# service httpd restart 停止 httpd: [确定] 启动 httpd:httpd: apr_sockaddr_info_get() failed for ser2.example.com httpd: Could notreliably determine the server's fully qualified domain name, using 127.0.0.1for ServerName 服务启动成功单出现提示表示不能解析ser2.example.com
AWstats日志分析
[root@localhost~]# cd /root/Desktop/ [root@localhostDesktop]# ls awstats-7.1.tar.gz [root@localhostDesktop]# tar zxf awstats-7.1.tar.gz -C /usr/local [root@localhostDesktop]# cd /usr/local/ [root@localhostlocal]# ls awstats-7.1 bin etc games include lib lib64 libexec sbin share src [root@localhostlocal]# mv awstats-7.1 awstats [root@localhostlocal]# ls awstats bin etc games include lib lib64 libexec sbin share src [root@localhostlocal]# cd awstats/ [root@localhostawstats]# ls docs README.TXT tools wwwroot [root@localhostawstats]# cd tools/ [root@localhosttools]# ls awstats_buildstaticpages.pl awstats_exportlib.pl geoip_generator.pl logresolvemerge.pl nginx webmin awstats_configure.pl awstats_updateall.pl httpd_conf maillogconvert.pl urlaliasbuilder.pl xslt
安装软件包(源码包安装),执行pl文件
[root@localhosttools]# ./awstats_configure.pl Enter full configfile path of your Web server. Example:/etc/httpd/httpd.conf Example:/usr/local/apache2/conf/httpd.conf Example:c:\Program files\apache group\apache\conf\httpd.conf Config file path('none' to skip web server setup): >/etc/httpd/conf/httpd.conf Do you want me tobuild a new AWStats config/profile file(required if first install) [y/N] ?y What is the nameof your web site or profile analysis ? Example:www.mysite.com Example: demo Your web site,virtual server or profile name: > www.example.com In which directorydo you plan to store your config file(s) ? Default:/etc/awstats Directory path tostore config file(s) (Enter for default): > PressENTER to continue... PressENTER to finish...
编辑awstats配置文件
[root@localhosttools]# vim /etc/awstats/awstats.www.example.com.conf LogFile="/var/log/httpd/access_log" DirData="/var/lib/awstats" [root@localhosttools]# mkdir /var/lib/awstats
运行awstats。提取日志。
[root@localhosttools]# ./awstats_updateall.pl now Running'"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update-config=www.example.com -configdir="/etc/awstats"' to update config www.example.com Create/Updatedatabase for config "/etc/awstats/awstats.www.example.com.conf" byAWStats version 7.0 (build 1.975) From data in logfile "/var/log/httpd/access_log"... Phase 1 : Firstbypass old records, searching new record... Searching newrecords from beginning of log file... Phase 2 : Nowprocess new records (Flush history on disk after 20000 hosts)... Jumped lines infile: 0 Parsed lines infile: 75 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 75 new qualified records
重启服务
[root@localhosthtml]# service httpd restart 停止 httpd: [确定] 启动 httpd: [确定]
添加计划任务
[root@localhosthtml]# crontab -e */5 * * * */usr/local/awstats/tools/awstats_updateall.pl now [root@localhosthtml]# service crond restart 停止 crond: [确定] 启动 crond: [确定] [root@localhosthtml]# chkconfig crond on
由于访问路径过于复杂,设置一个较简单路径自动跳转到此页面。
[root@localhost ~]#vim /var/www/html/aw.html <html><head> <metahttp-equiv=refresh content="0; url=http://192.168.10.1/awstats/awstats.pl?config=www.example.com"> </head> <body></body></html> ~ [root@localhost~]# service httpd restart
基于域名的虚拟主机(使用最多)
[root@localhost~]# mkdir -p /data/www/html/www [root@localhost~]# mkdir -p /data/www/html/bbs [root@localhost~]# cd /data/www/html/www/ [root@localhostwww]# vim index.html [root@localhostwww]# vim ../bbs/index.html [root@localhosthttpd]# vim conf.d/vi.conf NameVirtualHost*:80 <VirtualHost*:80> DocumentRoot /data/www/html/www 网页文档存放位置 ServerName www.example.com域名 ErrorLoglogs/dummy-www.example.com-error_log 错误日志文件位置 CustomLoglogs/dummy-www.example.com-access_log common 访问日志 </VirtualHost> <VirtualHost*:80> DocumentRoot /data/www/html/bbs ServerName bbs.example.com ErrorLoglogs/dummy-bbs.example.com-error_log CustomLoglogs/dummy-bbs.example.com-access_log common </VirtualHost> [root@localhosthttpd]# service httpd restart
基于端口的虚拟主机(一般于测试时使用,开发环境)
[root@localhosthttpd]# vim conf.d/vi.conf #NameVirtualHost*:80 基于端口的不需要 Listen 81 监听81端口,在httpd主配置文件中已listen80,只需添加增加的端口,也可以在httpd.conf中添加 <VirtualHost192.168.10.1:80> DocumentRoot /data/www/html/www ServerName www.example.com不需要域名添加也可以 ErrorLoglogs/dummy-www.example.com-error_log CustomLoglogs/dummy-www.example.com-access_log common </VirtualHost> <VirtualHost192.168.10.1:81> DocumentRoot /data/www/html/bbs ServerName bbs.example.com ErrorLoglogs/dummy-bbs.example.com-error_log CustomLoglogs/dummy-bbs.example.com-access_log common </VirtualHost> [root@localhosthttpd]# service httpd restart
基于IP的虚拟主机
[root@localhostwww]# vim /etc/httpd/conf.d/vi.conf #NameVirtualHost*:80 <VirtualHost192.168.10.1> DocumentRoot /data/www/html/www ServerName www.example.com ErrorLoglogs/dummy-www.example.com-error_log CustomLog logs/dummy-www.example.com-access_logcommon </VirtualHost> <VirtualHost192.168.10.2> DocumentRoot /data/www/html/bbs ServerName bbs.example.com ErrorLoglogs/dummy-bbs.example.com-error_log CustomLoglogs/dummy-bbs.example.com-access_log common </VirtualHost> [root@localhostwww]# yum -y install php [root@localhostwww]# vim index.php <?php phpinfo(); ?> [root@localhostwww]# service httpd restart
源码包安装apachectl服务,目录路径为源码包的安装路径。注意主配置文件中的权限设置。源码包安装完成后,可根据下面操作将源码包服务添加到开机自启服务中。
[root@localhosthttpd]# cp /usr/local/httpd/bin/apachectl /etc/init.d/ [root@localhosthttpd]# cd /etc/init.d/ [root@localhostinit.d]# mv apachectl httpd [root@localhostinit.d]# vim httpd #chkconfig: 2345 56 30 #description:web server [root@localhost init.d]#chkconfig --add httpd [root@localhostinit.d]# service httpd stop [root@localhostinit.d]# service httpd start
转载于:https://blog.51cto.com/8588192/1371142