菜鸟学Linux 第052篇笔记  httpd-install and section2




apache 17years

NCSA, httpd

A Patchey Server = Apache

FSF (GNU, GPL Free Software Foundation)

ASF (Apache Software Foundation)

web: httpd

tomcat

Hadoop

www.apache.org

httpd:

Web Server, Open Source

httpd feature

事先创建进程

按需维持适当的进程

模块化设计,核心比较小,各种功能都可模块添加(包括php)

支持运行时配置,支持单独编译模块

支持多种方式的虚拟主机配置

Socket IP:Port

虚拟主机:

基于IP的虚拟主机

基于端口的虚拟主机

基于域名的虚拟主机

支持https协议  {mod_ssl}

支持用户认证

支持基于IP或主机的ACL

支持每目录的访问控制

支持URL重写

Redhat install httpd:

rpm包安装

源码编译安装

httpd受SELinux (由于未学,先让其处于permissive)

getenforce

setenforce 0

httpd file:

/usr/sbin/httpd (MPM:prefork)

httpd: root, root (master process)

httpd: apache, apache (worker process)

/etc/rc.d/init.d/httpd

port: (80/tcp) (ssl: 443/tcp)

/etc/httpd 工作的根目录,相当于程序安装目录

/etc/httpd/conf 主配置文件目录

主配置文件: httpd.conf

/etc/httpd/conf.d/*conf

/etc/httpd/modules 模块路径

/etc/httpd/logs --> /var/log/httpd 日志目录

日志文件有两类 访问日志access_log 错误日志 err_log

/var/www/

html 静态内容路径

cgi-bin 动态内容路径

cgi: Common Gateway Interface

Client --> httpd (index.cgi) --> Spawn process --> httpd --> Client

Perl, python, java(servlet, JSP), PHP

fastcgi 使http server和动态解释器分开(可以在物理分成两个服务器)

程序: 指令和数据

数据: 数据库服务 cpu-bound

LAMP

Linux

apache

MySQL

php

httpd 安装

yum install httpd

/etc/httpd/conf

httpd.conf

### Section 1: Global Environment

### Section 2: 'Main' server configuration (默认)

### Section 3: Virtual Hosts

(注意第二段和第三段不可同时生效,同一时间只可有一个生效)

directive value

指令不区分字符大小写

value则根据需要有可能要区分

loadRunner

测试web server (老师说不作讲解,自学,)

MPM: Multi-Path Modules

mpm_winnt

prefork (一个请求用一个进程响应)

worker (一个请求用一个线程响应, (启动多个进程,每个进程生成多个线程))

event (一个进程响应多个请求,生成子进程并且每个子进程生成多个线程)      



修改apache processing model (MPM)

/etc/sysconfig/httpd

#HTTPD=/usr/sbin/httpd.event   删除#号,后边加模块名字即可(需重启服务)

apache 2.2 有event为测试版,不建议使用  



Options

None: 不支持任何选项

Indexes: 允许索引目录

FollowSynLinks: 允许访问符号连接指向的原文件




Section 2: 'Main' server configuration

ServerAdmin root@localhost

ServerName 

DocumentRoot "/var/www/html"  (最后一个切记不要加斜线)


<Directory "/var/www/html">

Options 

Indexes(索引) 

FollowSymLinks(跟随符号链接) 

None

SymLinksifOwnerMatch

ExecCGI 允许执行CGI脚本

MUltiViews 

All

AllowOverride None

Order 用于定义基于主机的访问功能,IP,网络地址或主机定义访问控制机制

Order Allow,deny

allow from

deny from

e.g.

order deny,allow

deny from 192.168.11.5 192.168.11.3


地址的表示方式

IP

network/netmask

hostname: www.a.com

Domainname: a.com

partial IP: 172.16= 172.16.0.0/16

</Directory>

DirectoryIndex index.html index.html.var 



实现网站进行登录访问(不常用,了解即可)

    AllowOverride AuthConfig

    AuthType Basic

    AuthName "Restricted Site..."

    AuthUserFile "/etc/httpd/conf/htuser"

    AuthGroupFile "/etc/httpd/conf/htgroup"

#    Require user red

    Require group myusers


加入以上配置后生成htpasswd文件使用命令,后跟的是用户名

htpasswd -c -m /etc/httpd/conf/htuser hadoop  

-c Creat

-m Use MD5

组文件直接编辑即可

vim /etc/httpd/conf/htgroup

格式 Group: user1 user2 ...

myusers: hadoop



是否启用用户家目录建立个人网站页面(默认关闭)

<IfModule mod_userdir.c>   

UserDir disable

  #UserDir public_html

</IfModule>

访问方式: http://192.168.11.110/~userName

(注意:因为其它用户对用户的家目录没有访问权限,如果想要访问该用户的网页

  需要在其用户目录上o+x权限

  

DirectoryIndex index.html index.html.var 默认打开页面   

  

Alias /icons/ "/var/www/icons/" 别名 

访问方式 http://www.mysky.com/icons/ 注意别名有斜线,访问时也要加

  

  


elinks http://172.168.11.1  以纯文本显示网页

-dump 显示网页内容后退出,不产生交互

-source 显示源码




PV: Page View

UV: user view






总结

MPM (Multi-path Modules)  重点

定义网站文档目录

访问选项 Options

基于主机的访问控制

基于用户或组的访问控制

用户个人站点

错误日志

日志格式

访问日志 PV UV

路径别名