1、请描述一次完整的http请求处理过程;
– (1)客户端发送http请求
– (2)服务端建立或处理连接,接受请求或拒绝请求
– (3)接受请求:接受客户端对服务器某一资源的请求
– (4)处理请求:对请求报文进行解析,获取客户端请求的资源及请求方法等相关信息
– (5)访问资源:获取请求报文中请求的资源
– (6)构建响应报文
– (7)发送响应报文
– (8)记录日志
2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。
– prefork: 多进程模型,一个进程处理一个请求,会由一个主进程预先生成几个进程来随时响应,进程响应相对于较耗资源,所以并不适合大并发的请求处理,各个进程的故障并不互相影响,这应该最稳定的处理模型。
– worker: 多进程多线程模型,线程处理请求,会由一个主进程生成几个进程,进程生成线程来处理并发请求,同个进程里可以共享资源,所以整体来说worker模型比prefork的资源消耗少,但是都在一个进程的线程处理请求,线程的故障会影响整个进程,所以并不是很稳定。
– event: 事件驱动模型,是基于事件驱动的进程来工作的,一个进程可以响应多个请求,也是预先生成多个进程,但是采用专用的进程来监听套接字保持连接,因为监听套接字和保持TCP连接所需要的资源极小一个进程就可以处理大量的这种请求。
3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。
安装环境Centos 6
1、httpd-2.4
编译安装步骤:
(1)apr-1.4+
./configure –prefix=/usr/local/apr
make && make install
(2)apr-util-1.4+
./configure –prefix=/usr/local/apr-util
make && make install
(3)httpd-2.4
./configure
–prefix=/usr/local/httpd2.4
–sysconfig=/etc/httpd24
–enable-so
–enable-ssl
–enable-cgi
–enable-rewrite
–with-zlib
–with-pcre
–with-apr=/usr/local/apr
–with-apr-util=/usr/local/apr-util/
–enable-modules=most
–enable-mpms-shared=all
–with-mpm=prefork
make && make install
2、mariadb-10.1.22
(1) cmake-2.8.8
./configure && make && make install
(2) mariadb
cmake . -LH 预编译下
cmake .
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFIGDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
初始化数据
./mysql_db_install –basedir=/usr/local/mysql –datadir=/data/mysql –user=mysql
加载库和头文件
vim /etc/ld.so.conf.d/mariadb.conf
/usr/local/mariadb
ln -s /usr/local/mariadb/include /usr/include/mysql
3、php-7.1.3
./configure –prefix=/usr/local/php \
–sysconfdir=/usr/local/php/etc \
–with-curl \
–with-freetype-dir \
–with-gd \
–with-gettext \
–with-iconv-dir \
–with-kerberos \
–with-libdir=lib64 \
–with-libxml-dir \
–with-mysqli \
–with-openssl \
–with-pcre-regex \
–with-pdo-mysql=/usr/local/mariadb \
–with-pdo-sqlite \
–with-pear \
–with-png-dir \
–with-xmlrpc \
–with-xsl \
–with-zlib \
–with-apxs2=/usr/local/http2.4/bin/apxs \
–enable-bcmath \
–enable-libxml \
–enable-inline-optimization \
–enable-gd-native-ttf \
–enable-mbregex \
–enable-mbstring \
–enable-opcache \
–enable-pcntl \
–enable-shmop \
–enable-soap \
–enable-sockets \
–enable-sysvsem \
–enable-xml \
–enable-zip
make && make install
配置httpd.conf
加载模块 LoadModule php7_module modules/libphp7.so
添加MIME AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
配置虚拟主机
打开 # Virtual hosts
Include conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot “/www”
ServerName www.jusene.com
DirectoryIndex index.php
ErrorLog “logs/dummy-host.example.com-error_log”
CustomLog “logs/dummy-host.example.com-access_log” common
<Directory ‘/www’>
Options None
AllowOverride None
RequireAll all granted
</Directory>
</VirtualHost>
测试php:
vim /www/index.php
<?php
phpinfo();
?>
测试mysql
<?
$con=mysqli_connect(‘127.0.0.1′,’bbs’,’bbs’);
if($con){
print ‘ok’;
}
else {
print ‘fail’;
}
?>
下载wordpress的安装包,将它解压到/www上我们就可以按照步骤安装wordpress了。
4、建立httpd服务器(基于编译的方式进行),要求:
提供两个基于名称的虚拟主机:
– (a)www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1.err,访问日志为/var/log/httpd/www1.access;
– (b)www2.stuX.com,页面文件目录为/web/vhosts/www2;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/www2.access;
– (c)为两个虚拟主机建立各自的主页文件index.html,内容分别为其对应的主机名;
– (d)通过www1.stuX.com/server-status输出httpd工作状态相关信息,且只允许提供帐号密码才能访问(status:status);
<VirtualHost *:80>
DocumentRoot “/web/vhosts/www1”
ServerName www1.stuX.com
ErrorLog “/var/log/httpd/www1.err”
CustomLog “/var/log/httpd/www1.access” common
<Directory ‘/web/vhosts/www1’>
Options None
AllowOverride None
RequireAll all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “/www/vhosts/www2”
ServerName www2.stuX.com
ErrorLog “/var/log/httpd/www2.err”
CustomLog “/var/log/httpd/www2.access” common
<Directory ‘/www/vhosts/www2’>
Options None
AllowOverride None
RequireAll all granted
</Directory>
</VirtualHost>
加载模块
LoadModule status_module modules/mod_status.so <Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "status page"
AuthUserFile "/usr/local/httpd2.4/conf/.htpasswd"
Require valid-user
</Location>
5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;
– (1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu);
– (2)设置部门为Ops,主机名为www2.stuX.com,邮件为admin@stuX.com;
私有ca也建在同一台主机:
[root@node2 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
………………………………+++
.+++
e is 65537 (0x10001)
[root@node2 ssl]# ls
httpd.key
[root@node2 ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server’s hostname) []:www2.stuX.com
Email Address []:admin@stuX.com
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@node2 ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Feb 26 18:53:32 2017 GMT
Not After : Feb 26 18:53:32 2018 GMT
Subject:
countryName = CN
stateOrProvinceName = HA
organizationName = MageEdu
organizationalUnitName = Ops
commonName = www2.stuX.com
emailAddress = admin@stuX.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
FC:CA:DE:D8:79:17:B3:12:16:50:FD:27:B2:76:7F:84:AE:F6:8F:65
X509v3 Authority Key Identifier:
keyid:FD:CD:68:2D:2C:BF:71:2E:C7:91:AB:6F:60:20:29:65:2A:6F:82:88
Certificate is to be certified until Feb 26 18:53:32 2018 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@node2 ssl]# ls
httpd.crt httpd.csr httpd.key
[root@node2 ssl]#
加载配置
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
修改配置
DocumentRoot
ServerName
SSLCertificateFile
SSLCertificateKeyFile
6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。”
上面的编译为将php编译成httpd模块来实现的。结下来我们将它编译称fastcgi的方式来进行实现。
php-7.1.3
./configure –prefix=/usr/local/php \
–sysconfdir=/usr/local/php/etc \
–with-curl \
–with-freetype-dir \
–with-gd \
–with-gettext \
–with-iconv-dir \
–with-kerberos \
–with-libdir=lib64 \
–with-libxml-dir \
–with-mysqli \
–with-openssl \
–with-pcre-regex \
–with-pdo-mysql=/usr/local/mariadb \
–with-pdo-sqlite \
–with-pear \
–with-png-dir \
–with-xmlrpc \
–with-xsl \
–with-zlib \
–enable-fpm \
–enable-bcmath \
–enable-libxml \
–enable-inline-optimization \
–enable-gd-native-ttf \
–enable-mbregex \
–enable-mbstring \
–enable-opcache \
–enable-pcntl \
–enable-shmop \
–enable-soap \
–enable-sockets \
–enable-sysvsem \
–enable-xml \
–enable-zip
make && make install
vim /etc/httpd.conf
加载这两个模块
mod_proxy.so
mod_proxy_fcgi.so
添加 MIME
AddType application/x-httpd-php-source .phps
这个要在虚拟主机前面加上,就因为在后面加导致找不到文件。
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
原创文章,作者:N25_随心,如若转载,请注明出处:http://www.178linux.com/72097
评论列表(1条)
如果可以多注意一下排版问题的话会更好