项目生产环境:
操作系统: CentOS release 6.9 (Final)
需要的软件:
httpd-2.4.23.tar.gz
apr-1.5.2.tar.gz
apr-util-1.5.4.tar.gz
项目任务: 搭建 Nginx+Apache 环境
项目目的: Nginx 处理静态请求, 动态请求交给 Apache 和 PHP 进行处理. 即 Nginx 作为前端 web 服务器, 而 Apache 在后端只处理动态请求, 实现动静态分离.
Nginx 安装步骤: http://blog.51cto.com/sky9896/1791629
Apache 的安装与使用:
- [root@sky9890 tools]# pwd
- /tools
1. 获取软件:
- [root@sky9890 tools]#
- wget http://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz
- [root@sky9890 tools]#
- Wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
- [root@sky9890 tools]#
- Wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
- [root@sky9890 tools]#
- Wget http://exim.mirror.fr/pcre/pcre-8.10.tar.gz
2. 安装基础包:
[root@sky9890 tools]# yum install gcc gcc-c++ zlib zlib-devel openssl openssl-devel libtool pcre-devel openssl-devel -y
3. 安装配置环境
- [root@sky9890 tools]# tar -zxvf httpd-2.4.23.tar.gz
- [root@sky9890 tools]# tar -zxvf apr-1.5.2.tar.gz
- [root@sky9890 tools]# tar -zxvf apr-util-1.5.4.tar.gz
- [root@sky9890 tools]# mv apr-1.5.2 httpd-2.4.23/srclib/apr
- [root@sky9890 tools]# mv apr-util-1.5.4 httpd-2.4.23/srclib/apr-util
- [root@sky9890 pcre-8.10]# ./configure --prefix=/usr/local/pcre && make && make install
- [root@sky9890 httpd-2.4.23]#
- ./configure \
- --prefix=/usr/local/apache2 \
- --enable-mods-shared=all \
- --enable-deflate \
- --enable-speling \
- --enable-cache \
- --enable-file-cache \
- --enable-disk-cache \
- --enable-mem-cache \
- --enable-ssl \
- --with-ssl=/usr/local/openssl/ \
- --enable-rewrite \
- --enable-so \
- --with-apr=/usr/local/apr/ \
- --with-apr-util=/usr/local/apr-util/ \
- --with-pcre=/usr/local/pcre \
--with-included-apr
- [root@sky9890 httpd-2.4.23]#make && make install
- [root@sky9890 bin]# pwd
- /usr/local/apache2/bin
- [root@sky9890 bin]# ./apachectl # 启动服务
- AH00557: httpd: apr_sockaddr_info_get() failed for sky9890
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the'ServerName' directive globally to suppress this message
- (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
- AH00015: Unable to open logs
- #ServerName www.example.com:80 http://www.example.com/
- #把 httpd.conf 文件中该行的 #去掉
- # nginx 占用了 80 端口号
- [root@sky9890 /]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
- AliYunDun 1410 root 18u IPv4 9251 0t0 TCP 172.19.68.202:37408->106.11.68.13:http (ESTABLISHED)
- nginx 2123 root 6u IPv4 11508 0t0 TCP *:http (LISTEN)
- nginx 2124 nobody 6u IPv4 11508 0t0 TCP *:http (LISTEN)
- [root@sky9890 conf]# vi httpd.conf
Listen 8080 #修改成 8080 端口, 不冲突了
- [root@sky9890 bin]# ./apachectl
- AH00557: httpd: apr_sockaddr_info_get() failed for sky9890
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the'ServerName' directive globally to suppress this message
- [root@sky9890 /]# lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
- httpd 17207 root 3u IPv4 55500 0t0 TCP *:webcache (LISTEN)
- httpd 17208 daemon 3u IPv4 55500 0t0 TCP *:webcache (LISTEN)
- httpd 17209 daemon 3u IPv4 55500 0t0 TCP *:webcache (LISTEN)
- httpd 17210 daemon 3u IPv4 55500 0t0 TCP *:webcache (LISTEN)
- httpd 17306 daemon 3u IPv4 55500 0t0 TCP *:webcache (LISTEN)
后续配置 (优化 Apache)
- [root@sky9890 /]# vi /etc/init.d/httpd
- #!/bin/bash
- #chkconfig:35 85 15
- /usr/local/apache2/bin/apachectl $1
- [root@sky9890 /]# chmod +x /etc/init.d/httpd
- [root@sky9890 /]# service httpd stop
httpd (no pid file) not running
- [root@sky9890 /]# service httpd start
- [root@sky9890 /]# service httpd restart
测试地址: http://101.132.79.69:8080/
It works!
Apache 的基本配置及动态分离配置, 下节分享.
来源: http://www.bubuko.com/infodetail-2566278.html