天天看点

apache服务器详细配置

---------------------------------------------

配置文件  RPM 包安装

Apache  /etc/httpd/conf/httpd.conf

--------------------------------------------

apache 配置文件

--------------------------------

serverRoot "/etc/httpd"

ServerRoot用于指定apache服务器的配置

文件及日志文件存放的根目录,默认为目录

“/etc/httpd”

pidFile /var/run/httpd.id

  PidFile 用于指定记录httpd进程号(pid)的文件

位置,默认值为“/var/run/httpd.pid”

MaxKeepAilveRequests 100

 每次连接可提出请求的数量,设置为0为不限,默认为100

KeepAileTimeout 15

连接两个请求之间的时间如果超过15秒还未到达,则视为连接

中断

DocumentRoot "/var/www/html"

指定apache服务器存放网页的文档根目录

##################################

UserDir

UserDir public_html

UserDir 用于设定用户个人主页存放的目录,默认为

“public_html”目录,即用/home/anyuser/public_html

为每个用户配置跟人主页

例如:为用户user1建立个人主页

cd /home/user1

mkdir public_html

chown user1.user1 public_html

cd ..

 chmod 711 user1

在/home/user1/public_html中建立index.html

使用浏览器http://localhost/~user1/

虚拟用户

############################################

Alias  用于设置路径别名

  Alias /doc/ /usr/share/doc/

   给 "/usr/share/doc" 设置路径别名为“/doc/”

************************************************

容器

<Directory / >     设置“/”根目录的访问权限

options

AllowOverride

Order

Allow

Deny

</ Directory>

五个属性

options 属性

options FollowSymLinks Indexes MultiViews

Options 可以组合设置下列选项

ALL:用户可以在此目录中做任何事情。

ExecCGI:允许在此目录中实行CGI程序

FollowSymLinks: 服务器可使用符号链接指向的文件或目录。

Indexes:服务器可生成此目录的文件列表。

None:不允许访问此目录。

AllowOverride None

AllowOverride 会根据设定的值决定是否读取目录中的

.htaccess文件,来改变运来所设置的权限。

All:读取.htaccess文件的内容,修改原来的访问权限

None:不读取.htaccess文件

为避免用户自行建立.htaccess文件修改访问权限,http.conf

文件中默认设置每个目录为:AllowOverride None.

AccessFileName filename

AccessFileName 指令用于指定保护目录设定文件的

文件名称,默认为“.htaccess”

AccessFileName .acl

-----------------------------------

APACHE虚拟目录

虚拟目录的优点:

便于访问

便于移动站点目录

加大磁盘空间

安全性好

Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons">

    Options Indexes MultiViews

    AllowOverride None

    Order allow,deny

    Allow from all

</Directory>

*******************************

首先在/etc/httpd/conf/httpd.conf

添加  Include vhost/vhost.conf

然后在 /etc/httpd/下创建 mkdir vhost

cd  vhost

vi vhost.conf 添加如下内容

 Alias /test1 "/root/web/test1/"

<Directory "/root/web/test1">

     AllowOverride None

Alias /test2 "/root/web/test2/"

<Directory "/root/web/test2">

然后改变 chmod 755 -R /root/web/test1

         chmod 755 -R /root/web/test2

http://localhost/test1

http://localhost/test2

可以增加权限的设置。。。

apache 虚拟目录

deny 和allow 访问列表的几种形式

*******************************************

认证和授权

认证类型

basic(常用)  digest(再要认证)不常用

建立认证与授权的步骤

   建立用户库

   配置服务器的保护域

   什么用户具有访问权限

认证指令

    Authname           受保护领域名称

    Authtype            认证方式

    Authuserfile        认证口令文件

    Authgroupfile       认证组文件

    Require use         授权指定用户

    Require group       授权指定组

    Require valid-user  授权给认证口令文件用户

建立用户库基本认证

   htpasswd -c authfile username

  口令文件格式

       username:password

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

用户认证:

例如:给添加认证

    authtype basic

    authname "welcome test"

    authuserfile /etc/httpd/httppwd

    require Valid-user = user test

  cd /etc/httpd 下实行  建立用户名和密码

               文件名 用户名

   htpasswd -c httppwd test

如果要添加多个用户那么只要第一使用过-c;以后都不用

 htpasswd httppwd aaa

并在添加  Alias /test2 "/root/web/test2/"

   require Valid-user = user test aaa

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

用户组授权

    allowOverride None

    authname "welcome admin"

    authgroupfile /etc/httpd/httpgrp

    require group admin

vi httpgrp  添加 如下内容:

   admin:test aaa

必须在/etc/httpd/httppwd 和/etc/httpd/httpgrp 都存在相同的用户

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

用.htaccess 文件授权

    AllowOverride all  

 vi /var/www/test2/.htaccess

     authtype basic

    require Valid-user

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

建立虚拟web站点

   基于IP地址的虚拟主机;基于域名的虚拟主机(同IP,不同端口)

基于IP的虚拟主机的配置

<VirtualHost 169.254.1.234:80>

    ServerAdmin [email protected]

    DocumentRoot /root/web/test1/

</VirtualHost>

<VirtualHost 169.254.1.233:80>

   ServerAdmin [email protected]

   DocumentRoot /root/web/test3/

基于端口的虚拟主机配置

  Listen 81

  Listen 82

<VirtualHost 169.254.1.234:81>

    ServerName 169.254.1.234:81

<VirtualHost 169.254.1.234:82>

    DocumentRoot /root/web/test3/

    ServerName 169.254.1.234:82

-------------------------------------