rhel6.5--http练习
包名 |
简介 |
httpd-2.2.15-29.el6_4.x86_64.rpm | http服务的主程序包 |
httpd-devel-2.2.15-29.el6_4.x86_64.rpm | apache的开发程序包,如一些附加的开发模块 |
httpd-tools-2.2.15-29.el6_4.x86_64.rpm | apache的工具,如htpasswd |
httpd-manual-2.2.15-29.el6_4.noarch.rpm | apoache的帮助文档 |
apr-1.3.9-5.el6_2.x86_64.rpm | 安装http-devel的时候,依赖包 |
apr-devel-1.3.9-5.el6_2.x86_64.rpm | |
apr-util-1.3.9-3.el6_0.1.x86_64.rpm | |
apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm | |
expat-2.0.1-11.el6_2.x86_64.rp | |
expat-devel-2.0.1-11.el6_2.x86_64.rpm |
安装:
[root@master ~]# rpm -ivh /media/cdrom/Packages/expat-devel-2.0.-.el6_2.x86_64.rpm
[root@master ~]# rpm -ivh /media/cdrom/Packages/apr-util-devel-1.3.-.el6_0..x86_64.rpm
[root@master ~]# rpm -ivh /media/cdrom/Packages/apr-devel-1.3.-.el6_2.x86_64.rpm
[root@master ~]# rpm -ivh /media/cdrom/Packages/httpd-2.2.-.el6_4.x86_64.rpm
[root@master ~]# rpm -ivh /media/cdrom/Packages/httpd-manual-2.2.-.el6_4.noarch.rpm
或者YUM直接安装
[root@master ~]# yum install -y httpd httpd-devel
启动服务
[root@master ~]# service httpd start
Starting httpd: [ OK ]
[root@master ~]# netstat -antup | grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /rpc.statd
tcp ::: :::* LISTEN /httpd
tcp ::: :::* LISTEN /rpc.statd
udp 0.0.0.0: 0.0.0.0:* /rpc.statd
udp 0.0.0.0: 0.0.0.0:* /rpc.statd
udp ::: :::* /rpc.statd
使用elinks查看服务是否正常
[root@master ~]# yum install -y elinks [root@master ~]# elinks 192.168.30.130 --dump
Red Hat Enterprise Linux Test Page This page is used to test the proper operation of the Apache HTTP server
after it has been installed. If you can read this page, it means that the
Apache HTTP server installed at this site is working properly.
-------------------------------------------------------------------------- If you are a member of the general public: The fact that you are seeing this page indicates that the website you just
visited is either experiencing problems, or is undergoing routine
maintenance. If you would like to let the administrators of this website know that
you've seen this page instead of the page you expected, you should send
them e-mail. In general, mail sent to the name "webmaster" and directed to
the website's domain should reach the appropriate person. For example, if you experienced problems while visiting www.example.com,
you should send e-mail to "webmaster@example.com". For information on Red Hat Enterprise Linux, please visit the []Red Hat,
Inc. website. The documentation for Red Hat Enterprise Linux is
[]available on the Red Hat, Inc. website. -------------------------------------------------------------------------- If you are the website administrator: You may now add content to the directory /var/www/html/. Note that until
you do so, people visiting your website will see this page, and not your
content. To prevent this page from ever being used, follow the
instructions in the file /etc/httpd/conf.d/welcome.conf. You are free to use the image below on web sites powered by the Apache
HTTP Server: [][ Powered by Apache ] References Visible links
. http://www.redhat.com/
. http://www.redhat.com/docs/manuals/enterprise/
. http://httpd.apache.org/
配置文件介绍
[root@master ~]# ls /etc/httpd/conf //核心配置文件httpd.conf
httpd.conf magic
[root@master ~]# ls /etc/httpd/conf.d/ //核心配置文件httpd.conf中的默认include文件位置
manual.conf README welcome.conf
[root@master ~]# ls /var/log/httpd/access_log // 默认访问日志
/var/log/httpd/access_log
[root@master ~]# ls /var/log/httpd/error_log //默认错误日志
/var/log/httpd/error_log
[root@master ~]# ls /var/www/html/ //默认网站根目录
hha install.log
[root@master ~]# ls /etc/httpd/run/httpd.pid //默认进程pid
/etc/httpd/run/httpd.pid
[root@master ~]# ls /var/www/manual/ //http-manu安装生成的apache手册
bind.html dso.html index.html mpm.html sitemap.html
caching.html env.html install.html new_features_2_0.html ssl
configuring.html faq invoking.html new_features_2_2.html stopping.html
content-negotiation.html filter.html LICENSE platform style
convenience.map glossary.html license.html programs suexec.html
custom-error.html handler.html logs.html rewrite upgrading.html
developer howto misc sections.html urlmapping.html
dns-caveats.html images mod server-wide.html vhosts
[root@master ~]# ls /etc/httpd/modules/ //默认库文件位置,模块目录
mod_actions.so mod_authz_owner.so mod_ext_filter.so mod_proxy_ftp.so
mod_alias.so mod_authz_user.so mod_filter.so mod_proxy_http.so
mod_asis.so mod_autoindex.so mod_headers.so mod_proxy_scgi.so
mod_auth_basic.so mod_cache.so mod_ident.so mod_proxy.so
mod_auth_digest.so mod_cern_meta.so mod_include.so mod_reqtimeout.so
mod_authn_alias.so mod_cgid.so mod_info.so mod_rewrite.so
mod_authn_anon.so mod_cgi.so mod_ldap.so mod_setenvif.so
mod_authn_dbd.so mod_dav_fs.so mod_log_config.so mod_speling.so
mod_authn_dbm.so mod_dav.so mod_log_forensic.so mod_status.so
mod_authn_default.so mod_dbd.so mod_logio.so mod_substitute.so
mod_authn_file.so mod_deflate.so mod_mime_magic.so mod_suexec.so
mod_authnz_ldap.so mod_dir.so mod_mime.so mod_unique_id.so
mod_authz_dbm.so mod_disk_cache.so mod_negotiation.so mod_userdir.so
mod_authz_default.so mod_dumpio.so mod_proxy_ajp.so mod_usertrack.so
mod_authz_groupfile.so mod_env.so mod_proxy_balancer.so mod_version.so
mod_authz_host.so mod_expires.so mod_proxy_connect.so mod_vhost_alias.so
配置文件介绍
[root@master ~]# vim /etc/httpd/conf/httpd.conf
ServerTokens OS //返回操作系统类型,如apache/2.0.54(unix)
ServerRoot "/etc/httpd" //服务器配置文件目录
PidFile run/httpd.pid //apache运行进程ID存放
Timeout 60 //超时时间,多少s没有反应就超时
KeepAlive Off //是否允许一个永久的链接,设置为OFF的时候,不能保持连接功能,传输效率比较低,设置为ON时,可以提高服务器传输文件的效率,建议开启
MaxKeepAliveRequests 100 //设置KeepAlive为ON时,设置客户端每次连接允许请求相应最大文件数,默认100个
KeepAliveTimeout 15 //超时时间,同一个客户端下一个请求15s没收到就超时
<IfModule prefork.c> //
StartServers 8 //服务开始启动8个进程
MinSpareServers 5 //最小空闲5个进程
MaxSpareServers 20 //最多空闲20个进程
ServerLimit 256 //服务器允许配置进程数上线
MaxClients 256 //最大连接数256,超过要进入等候队列
MaxRequestsPerChild 4000 //每个进程生存周期内服务最大的请求数量
</IfModule>
Listen 80 //监听端口
Include conf.d/*.conf //conf.d里面的conf文件也属有效配置文件
#ExtendedStatus On //
User apache // 指定apache以什么用户运行
Group apache //指定apache以哪个组运行
ServerAdmin root@localhost //管理员邮箱
ServerName 192.168.30.130:80 // 服务器主机名
<Directory "/var/www/html"> // 默认主目录
Options Indexes FollowSymLinks //
AllowOverride None //
Order allow,deny //默认deny生效
Allow from all //允许所有
</Directory> DirectoryIndex index.html index.html.var //首页
AccessFileName .htaccess //access文件名 TypesConfig /etc/mime.types //
DefaultType text/plain //
<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime //
MIMEMagicFile conf/magic //
</IfModule> ErrorLog logs/error_log //
LogLevel warn //日志等级
CustomLog logs/access_log combined //
ServerSignature On //
Alias /icons/ "/var/www/icons/" //
<Directory "/var/www/icons"> //
Options Indexes MultiViews FollowSymLinks //目录浏览,FollowSynLinks用链接浏览
AllowOverride None //设置为none,忽略.htaccess
Order allow,deny //
Allow from all //
</Directory>
# Example:
# LoadModule foo_module modules/mod_foo.so //载入的模块
AddDefaultCharset UTF-8 //默认编码格式
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z //
AddType application/x-gzip .gz .tgz //
#NameVirtualHost *:80 //
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example: // 虚拟主机配置格式如下,具体配置项说明请参见官方文档:http://httpd.apache.org/docs/2.2/
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80> //
# 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 //
#</VirtualHost>
实例1:搭建一台web服务器
#如果需要修改默认网站根目录需要修改两处,
DocumentRoot "/var/www/html"和<Directory "/var/www/html">
[root@master ~]# vim /etc/httpd/conf/httpd.conf
ServerName 192.168.30.130:
ServerAdmin root@192.168.30.130
#先改这两处,其他不要动
浏览器访问
创建一个测试页
[root@master ~]# vim /var/www/html/test.html
<h1><b>This is a test page!</b></h1>
重启httpd服务,访问测试
实例2:更改网站根目录,并设置访问权限
[root@master ~]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/sishen"
<Directory "/var/www/html/sishen">
Options FollowSymLinks #原值为Options Indexes FollowSymLinks=允许访问目录;FollowSymLinks不允许访问目录
Order allow,deny
Allow from 192.168.30.101/
Deny from 192.168.30.130 //只是举个例子,也可以写IP段,Allow和Deny冲突的时候,Deny如果在后面Deny生效,不冲突都生效
</Directory>
访问测试访问目录
禁止访问目录,没问题
测试禁止段IP地址访问(服务端IP地址为192.168.30.130)
禁止访问,没问题
测试允许段IP地址访问(slave1的IP地址为192.168.30.132)
可以访问没问题。
如果将这里反过来写,allow在后面则相当于允许所有
宿主机也可以访问,宿主机IP(172网段)
实例3:网站别名
创建测试目录及修改配置文件
[root@master ~]# mkdir /usr/local/phpdate
[root@master ~]# echo "This is a PHPData Directory" > /usr/local/phpdate/index.html
[root@master ~]# vim /etc/httpd/conf/httpd.conf
Alias /phpdata/ "usr/local/phpdata/ # 这里需要注意的是名字起什么无所谓,但必须以/结束
<Directory "/usr/local/phpdata">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
重启服务测试
可以访问,没问题。
实例4:修改配置文件,支持目录访问
[root@master ~]# cp -r /etc/sysconfig/network-scripts/* /var/www/html/sishen/
[root@master ~]# vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks //加上Indexes支持目录访问
可以访问没问题。
实例5:软连接功能
通过软连接,我们可以直接引用网站根目录外面的内容,我们通过目录浏览的方式,在/var/www/html/sishen/面创建一个web2目录, 然后我访问web2目录的话,实际访问的是/usr/local/alias下面的内容
[root@master ~]# mkdir /usr/local/alias
[root@master ~]# cp /var/www/html/sishen/* /usr/local/alias/
[root@master ~]# mkdir /var/www/html/sishen/web2
[root@master ~]# ln -s /usr/local/alias/ /var/www/html/sishen/web2/
就会跳转到
点击alias
实例6:网站认证
方法一
[root@master ~]# vim /etc/httpd/conf/httpd.conf
<Directory "/usr/local/phpdata/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
authtype basic
authname "This is a Auth Test"
authuserfile /etc/httpd/conf/passwd.secret
require valid-user #这里可以写为user1 user2,(user1和user2中间用空格分开)这样写说明user1和user2都可以访问
</Directory>
创建认证用户
[root@master ~]# htpasswd -cm /etc/httpd/conf/passwd.secret user1
New password:
Re-type new password:
Adding password for user user1
[root@master ~]# htpasswd -m /etc/httpd/conf/passwd.secret
user2 //-c创建文件,所以第二次就不需要-c参数,-m表示md5加密方式
New password:
Re-type new password:
Adding password for user user2
[root@master ~]# cat /etc/httpd/conf/passwd.secret
user1:$apr1$9uyqlxl9$mt46QcIfuccYnQ95zrWId1
user2:$apr1$xqsKwkMp$0MrGw1DUWUUzVVBhpa9Lq/
重启服务测试(在实例5的基础上修改的配置文件)
可以访问,没问题。
方法二:
Alias /phpdata/ "/usr/local/phpdata/"
<Directory "/usr/local/phpdata/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
# authtype basic
# authname "This is a Auth Test"
# authuserfile /etc/httpd/conf/passwd.secret
# require valid-user
AllowOverride Authconfig
</Directory>
[root@master ~]# vim /usr/local/phpdata/.htaccess
authtype basic
authtype basic
authname "This is a Auth Test"
authuserfile /etc/httpd/conf/passwd.secret
require valid-user
重启服务测试
可以访问没问题。
实例7:虚拟主机
修改配置文件(基于实例6的配置文件)
[root@master ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.30.130:>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 192.168.30.131:>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/sishen
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
重启服务访问测试
实例8:基于不同端口的虚拟主机
[root@master ~]# vim /etc/httpd/conf/httpd.conf
Listen
Listen 8080 //原有基础上添加这行
.....
<VirtualHost 192.168.30.130:>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 192.168.30.131:>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/sishen
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
重启服务测试
如果不加8080默认的131访问的也是/var/www/html
加上8080
实例9:基于不同域名的访问
修改配置文件
[root@master ~]# vim /etc/httpd/conf/httpd.conf
Listen
Listen NameVirtualHost *:
NameVirtualHost *: <VirtualHost *:>
ServerAdmin webmaster@www.haha.com
DocumentRoot /var/www/html
ServerName dummy-host.haha.com
ErrorLog logs/dummy-host.haha.com-error_log
CustomLog logs/dummy-host.haha.com-access_log common
</VirtualHost>
<VirtualHost *:>
ServerAdmin webmaster@www.xixi.com
DocumentRoot /var/www/html/sishen
ServerName dummy-host.xixi.com
ErrorLog logs/dummy-host.xixi.com-error_log
CustomLog logs/dummy-host.xixi.com-access_log common
</VirtualHost>
修改宿主机hosts文件
C:\Windows\System32\drivers\etc\hosts
末尾添加
192.168.30.130 www.haha.com
192.168.30.131 www.xixi.com
重启服务访问测试
实例10:URL地址重写(伪静态)
首先确认httpd.conf中是否有这个LoadModule rewrite_module modules/mod_rewrite.so模块
创建测试页面
[root@master ~]# vim /var/www/html/index.php
<?php
echo "The Page....".$GET['id']."....Pages"
?>
修改配置文件
[root@master ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost *:>
ServerAdmin webmaster@www.haha.com
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerName dummy-host.haha.com
ErrorLog logs/dummy-host.haha.com-error_log
CustomLog logs/dummy-host.haha.com-access_log common
</VirtualHost>
添加伪静态规则
[root@master ~]# vim /var/www/html/.htaccess
RewriteEngine on
RewriteRule ^index(\d+).html$ index.php?id=$
重启服务访问测试(输入一个不存在的页面)
实例11:自定义404
修改.htaccess文件,使支持自定义404
[root@master ~]# vim /var/www/html/.htaccess
RewriteEngine on
RewriteRule ^index(\d+).html$ index.php?id=$
ErrorDocument /.html //添加此行
创建测试页面
[root@master ~]# echo "This is a 404 Page,hahaha" >/var/www/html/.html
重启服务测试
实例12:301重定向配置
假设a.com在某些情况下不能使用,需要将网站全部迁移到b.com,那么我们这个时候就可以对a.com进行301重定向,这样a.com(上的权重,SEO里面的知识)传递到b.com上,这个主要用来实现整站迁移
[root@master ~]# vim /var/www/html/.htaccess RewriteCond %{HTTP_HOST} ^a.com [NC]
RewriteRule ^(.*)$http://www.b.com/$1 [L,R=301]
rhel6.5--http练习的更多相关文章
- RHEL6和RHEL7恢复root用户密码
一.RHEL6恢复root密码 将系统重启,出现如下界面按上下键选择会停住,并输入e键 选中下图红框选项,再输入e键 再输入1,进入单用户模式 输入b进行启动 修改密码,然后重启 二.RHEL7恢 ...
- RHEL6 64位系统安装ORACLE 10g 64bit 数据库
记得去年4月份的时候,为公司部署测试环境和UAT环境时,在红帽RHEL6 64位系统安装ORACLE 10g 64位数据库时遇到了许多小问题,当时匆匆忙忙也没记录一下这些问题,前几天在虚拟机安装ORA ...
- RHEL7.2和RHEL6.5的配置网络yum源和本地yum源
RHEL7.2配置本地yum源 [root@localhost ~]#monut /dev/sr0 /mnt #挂载光盘 [root@localhost ~]# rm -rf /etc/yu ...
- RHEL6.5 换源
由于redhat的yum在线更新要收费,即没有注册的无法使用:将redhat的yum卸载.重装第三方源. 第三方源包括:网易,重庆大学,epel 等Author wood_man.2015.10.2 ...
- Linux之RHEL6的开机流程分析
开机——很多人觉得很简单的事情,只要按下电源开关,然后系统就会自然启动,没有什么需要学习的.其实不然,如果系统没有什么问题,可以正常登陆的时候,当然开机很简单.但更多的时候,我们需要知道当机子不能正常 ...
- RHEL6.6 PXE安装-基于VMWare WorkStation
///////////第一部分:安装安装服务器 1.先安装一台RHEL6.6的服务器A(地址为192.168.139.132),作为安装服务器.这样后面的机器就可以指向这台服务器进行自动安装 2.在A ...
- RHEL6.5及Win7的和谐共处(投机版)
背景: 在Windows XP存在时,装了个RHEL6.5,用的是安装程序自带的Grub,后来将XP删除后重装了Windows7,RHEL的Grub被覆盖,启动不了RHEL了,于是补上RHEL的引导… ...
- RHEL6.2下挂载光驱安装软件
导读 在RHEL6.2命令行模式下挂载虚拟光驱安装软件也许会难倒许多新手,下面我给大家详细介绍一下.首先说明一下,本教程是以RHEL6.2版本下安装Apache为例.主要讲述挂载虚拟光驱的方法.环境: ...
- 《postfix MAIL服务搭建(第一篇):》RHEL6
初级篇:搭建发送端.接收端.邮件别名的添加从而达到邮件群发功能的实现. 我们都知道邮件服务器是2个服务端也就是说2个端口,一个是发送的端口,一个是收邮件的端口,我们平常所使用的发送,接收邮件的过程,只 ...
- 手把手VirtualBox虚拟机下安装rhel6.4 linux 64位系统详细文档
下面演示安装的是在VirtualBox里安装rhel 6.4 linux 64位系统. 一.VirtualBOX 版本. 二.虚拟机的配置. 1.现在开始演示安装,一起从零开始.点击“新建”,创建新的 ...
随机推荐
- bind_ip
https://docs.mongodb.com/manual/reference/configuration-options/index.html 192.168.2.* --23T10:: I C ...
- Oracle Exception
Oracle存储过程的异常处理 1.为了提高存储过程的健壮性,避免运行错误,当建立存储过程时应包含异常处理部分.2.异常(EXCEPTION)是一种PL/SQL标识符,包括预定义异常.非预定义异常和自 ...
- Axure Base 03
(三)Axure rp元件的触发事件 l OnClick(点击时): 鼠标点击事件,除了动态面板的所有的其他元件的点击时触发.比如点击按钮. l OnMouseEnter(鼠标移入时): 鼠标进入 ...
- Delphi中取得汉字的首字母简单方法(十分巧妙)
//从朝闻道的博客里转载,原文定义AHzStr: String,发现结果为空,后来改成AHzStr: AnsiString就可以了 function GetHzPy(const AHzStr: Ans ...
- 处理TCP连包的一小段代码
学习网络编程也有一段时间了,一直听说TCP数据会连包,但一直不知道怎么测试好.最近测试了下:发送方使用对列,将发送的数据存入队列,然后开线程,专门发送.发送多包数据之间不延时.在接收方,他们确实连在一 ...
- 学习js所必须要知道的一些
1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...
- get all sites under IIS
https://stackoverflow.com/questions/2555668/how-to-programmatically-get-sites-list-and-virtual-dirs- ...
- 解决IE浏览器部分版本不支持background-size属性问题
background-size是CSS3新增的属性,现在有很多浏览器都支持CSS3了.但是IE浏览器有些版本还是不支持,比如IE8,IE9也有些CSS3的属性会支持,但是有些也不支持.在这里就了解一下 ...
- MYSQL初级学习笔记五:连接查询!(视频序号:初级_37-41)
知识点七:连接查询(37-41) 什么是连接查询: 连接查询是将两个或两个以上的表按某个条件连接起来,从中选取需要的数据.连接查询是同时查询两个或两个以上的表时使用的.当不同的表中存在相同意义的字段时 ...
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
在做一个view背景特效的时候被坐标的各个获取方法搞晕了,几篇抄来抄去的博客也没弄很清楚. 现在把整个总结一下. 其实只要把下面这张图看明白就没问题了. 涉及到的方法一共有下面几个: view获取自身 ...