Chinaunix首页 | 论坛 | 博客
  • 博客访问: 191809
  • 博文数量: 61
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-16 13:37
个人简介

努力不会成功,不努力一定不会成功!在路上的感觉永远没有到家的感觉好,差好多!

文章分类

全部博文(61)

文章存档

2017年(1)

2016年(4)

2015年(3)

2013年(45)

2012年(8)

分类: 系统运维

2013-07-22 13:17:56

 Apache服务器配置

一、准备

login as: root
password:
Last login: Tue Apr  9 11:11:42 2013 from 192.168.248.1
[root@vm2 root]# zh

二、操作

1、访问控制

[root@vm2 html]# vi /etc/httpd/conf/httpd.conf
AddDefaultCharset utf-8   //修改默认字符集为支持中文格式
[root@vm2 html]# apachectl restart  //重启apache服务
[root@vm2 html]# vi index.html  //创建默认网页index.html
[root@vm2 html]# ls
index.html 
[root@vm2 html]# cat index.html


哈哈哈

[root@vm2 html]#mkdir lab exam  //在文档根目录下(/var/www/html)创建两个目录
[root@vm2 html]# ls
exam  lab
[root@vm2 html]# vi index.html  //在根目录创建index.html主页


实验
考试


[root@vm2 html]# cd lab
[root@vm2 lab]# cat > lab1.txt
[root@vm2 lab]# cat > lab2.txt
//把文件lab1.txt和lab2.txt上传到网页

//浏览网页显示两个文件

实验 考试

//进入“实验”目录
Index of /lab
 Name                    Last modified      Size  Description-------------------------------------------------------------------------------- Parent Directory                             -  
 lab1.txt                09-Apr-2013 14:09  1.3K 
 lab2.txt                09-Apr-2013 14:08  1.2K

[root@vm2 lab]# vi .htaccess
[root@vm2 lab]# cat .htaccess
Option -Indexes   //设置网页格式为不生产目录列表

//浏览网页显示两个文件,说明配置未生效,lab网页仍然生成目录列表,原因是没有把文件权限归还给apache

Index of /lab
 Name                    Last modified      Size  Description-------------------------------------------------------------------------------- Parent Directory                             -  
 lab1.txt                09-Apr-2013 14:09  1.3K 
 lab2.txt                09-Apr-2013 14:08  1.2K

[root@vm2 lab]# chown -R apache:apache .. //把文件权限归还给apache
[root@vm2 lab]# vi /etc/httpd/conf/httpd.conf
 AllowOverride All    //修改主配置文件,允许局部控制(注意是在文档根目录下的AllowOverride,下)

[root@vm2 lab]# apachectl restart //重启服务

//浏览网页出现错误,没有显示两个文件
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster

//撤销上面的操作的话,就可以重新浏览网页。

 

2、个人主页

[root@vm2 lab]# vi /etc/httpd/conf/httpd.conf
 #UserDir disable    //把不允许用户访问注释掉
UserDir public_html  //去掉注释,开通个人主页

[root@vm2 lab]# apachectl restart  //个人主页生效
[root@vm2 lab]# su -yanji    //切换到yanji用户
[yanji@vm2 yanji]$ mkdir public_html  //创建public_html目录,在此放置个人主页文档,同时需要添加子目录为可访问的
[yanji@vm2 yanji]$ ls
public_html
[yanji@vm2 yanji]$ cd public_html
[yanji@vm2 public_html]$ vi index.html   //编辑一个网页文件
[yanji@vm2 public_html]$ cat index.html


人生自古谁无死


[yanji@vm2 public_html]$

//浏览IE网页,不能访问,说明不允许目录访问,修改权限,重启网页即可
Forbidden
You don't have permission to access /~yanji on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

[yanji@vm2 public_html]$ cd
[yanji@vm2 yanji]$ chmod o+x .  //对本身的其他用户添加执行权限
[yanji@vm2 yanji]$

//浏览IE网页,可以访问
人生自古谁无死

 

3、认证和授权

[yanji@vm2 yanji]$ su -  
Password:
[root@vm2 root]#          //回到超级用户
[root@vm2 root]# cd /var/www/html
[root@vm2 html]# ls
exam  index.html  lab  usage
[root@vm2 html]# cd lab
[root@vm2 lab]# cat > .htaccess     //把下面的内容添加到 .htaccess文件中
AuthType Basic
AuthName "linux"
AuthUserFile /var/www/users  //users目录用于存放用户信息文件
require valid-user
[1]+  Stopped                 cat >.htaccess

[root@vm2 lab]# htpasswd -c /var/www/users wang
New password:
Re-type new password:
Adding password for user wang
[root@vm2 lab]# htpasswd /var/www/users yang
New password:
Re-type new password:
Adding password for user yang    //添加两个用户“wang”和“yang”成功,首次添加用户需要加“-c”命令,这种方式适用于少量用户的添加。若是要创建大量的用户,则要用mysql来实现。

[root@vm2 lab]# chown apache:apache /var/www/users
[root@vm2 lab]#//设置用户名与主机名都是apache
可以用这两个用户访问网页了。

阅读(4582) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~