Nginx+Apache环境
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx+Apache环境相关的知识,希望对你有一定的参考价值。
项目生产环境:
操作系统: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的安装与使用:
[[email protected] tools]# pwd
/tools
1.获取软件:
[[email protected] tools]#
wget http://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz
[[email protected] tools]#
Wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
[[email protected] tools]#
Wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
[[email protected] tools]#
Wget http://exim.mirror.fr/pcre/pcre-8.10.tar.gz
2.安装基础包:
[[email protected] tools]# yum install gcc gcc-c++ zlib zlib-devel openssl openssl-devel libtool pcre-devel openssl-devel –y
3.安装配置环境
[[email protected] tools]# tar -zxvf httpd-2.4.23.tar.gz
[[email protected] tools]# tar -zxvf apr-1.5.2.tar.gz
[[email protected] tools]# tar -zxvf apr-util-1.5.4.tar.gz
[[email protected] tools]# mv apr-1.5.2 httpd-2.4.23/srclib/apr
[[email protected] tools]# mv apr-util-1.5.4 httpd-2.4.23/srclib/apr-util
[[email protected] pcre-8.10]# ./configure --prefix=/usr/local/pcre && make && make install
[[email protected] 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
[[email protected] httpd-2.4.23]#make && make install
[[email protected] bin]# pwd
/usr/local/apache2/bin
[[email protected] 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端口号
[[email protected] /]# 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)
[[email protected] conf]# vi httpd.conf
Listen 8080 #修改成8080端口,不冲突了
[[email protected] 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
[[email protected] /]# 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)
[[email protected] /]# vi /etc/init.d/httpd
#!/bin/bash
#chkconfig:35 85 15
/usr/local/apache2/bin/apachectl $1
[[email protected] /]# chmod +x /etc/init.d/httpd
[email protected] /]# service httpd stop
httpd (no pid file) not running
[[email protected] /]# service httpd start
[[email protected] /]# service httpd restart
测试地址:http://101.132.79.69:8080/
It works!
Apache的基本配置及动态分离配置,下节分享。
以上是关于Nginx+Apache环境的主要内容,如果未能解决你的问题,请参考以下文章
(Nginx +gunicorn)/Apache 不读取环境变量