项目生产环境:
操作系统: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在后端只处理动态请求,实现动静态分离。
实战技巧:如何解决80端口冲突的问题?
安装难点:apr、apr-util软件包的安装及Apache配置。
Nginx安装步骤:https://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 #把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的基本配置及动态分离配置,下节分享。