1. 程式人生 > >Nginx+Apache環境

Nginx+Apache環境

Nginx PHP

項目生產環境:

操作系統: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 #把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的基本配置及動態分離配置,下節分享。


Nginx+Apache環境