首页 技术 正文
技术 2022年11月21日
0 收藏 775 点赞 3,822 浏览 2985 个字

搭建过lamp博友和lnmp的博友们可能对这这两个单词并不陌生,对与apachen,nginx相比都源码或yum安装过,但知道apache的nginx的优点,apache处理动态页面很强,nginx处理静态页面丝毫不逊色。如果只是单独的去应用,在现行的高并发的企业网络体难以系上保证此架构的稳定性。

如果把apache和nginx相互整合,动静结合,可以很大程度上提高网络的处理效率。

下面是lanmp架构的简单搭建:

源码安装 LNAMP 之 Nginx

yum install prce-devel – y ;cd /usr/src ;wget
http://nginx.org/download/nginx-1.6.0.tar.gz ;cd nginx-1.6.0 ;./configure –
prefix=/usr/local/nginx && make &&make install

源码安装 LNAMP 之 Apache
yum install apr-devel apr-util-devel –y;
cd /usr/src ; wget
http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.27.tar.gz ;tar xzf
httpd-2.2.27.tar.gz ;cd httpd-2.2.27 ;./configure –prefix=/usr/local/apache
–enable-so –enable-rewrite &&make &&make install

源码安装 LNAMP 之 MySQL
cd /usr/src ;wget
http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.63.tar.gz ;tar xzf
mysql-5.1.63.tar.gz ;cd mysql-5.1.63 ;./configure –prefix=/usr/local/mysql
–enable-assembler &&make &&make install
配置 Mysql 服务为系统服务:
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

chkconfig –add mysqld
chkconfig –level 345 mysqld on
cd /usr/local/mysql
useradd mysql
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db –user=mysql
chown -R mysql var
/usr/local/mysql/bin/mysqld_safe –user=mysql &

lnamp高性能架构之apache和nginx的整合

源码安装 LNAMP 之 PHP
cd /usr/src ;wget http://mirrors.sohu.com/php/php-5.3.28.tar.bz2 ;tar jxf
php-5.3.28.tar.bz2 ;cd php-5.3.28 ;./configure –prefix=/usr/local/php5
–with-config-file-path=/usr/local/php/etc
–with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql/

lnamp高性能架构之apache和nginx的整合

源码安装 Apache+PHP 整合
整合 apache+php 环境,修改 httpd.conf 配置文件,然后加入如下语句:
LoadModule php5_module modules/libphp5.so (默认已存在)
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html (把 index.php 加入 index.html 之前)

lnamp高性能架构之apache和nginx的整合

然后在/usr/local/apache/htdocs 目录下创建 index.php 测试页面,执行如下命令:
cat >>/usr/local/apache/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF

重新启动 apache 服务,通过 IP 访问界面如下图,即代表 LAMP 环境搭建成功。

lnamp高性能架构之apache和nginx的整合

 源码安装 DISCUZ 论坛

下载 discuz 源码包文件,然后解压:
cd /usr/src ;wget
http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip
解压 discuz 程序包:unzip Discuz_X3.1_SC_UTF8.zip -d /usr/local/apache/htdocs/
重命名程序文件:cd /usr/local/apache/htdocs/ ;mv upload/* .
赋予 discuz 目录完全访问权限:cd /usr/local/apache/htdocs/ ;chmod 777 -R data/

uc_server/ config/ uc_client/          

然后访问 IP 安装 discuz 论坛,如下图,选择“我同意”

lnamp高性能架构之apache和nginx的整合

进入如下界面,数据库安装,如果不存在则需要新建数据库并授权。

lnamp高性能架构之apache和nginx的整合

数据库创建及授权命令如下:
create database discuz charset=utf8;
grant all on discuz.* to root@’localhost’ identified by “123456”;  

lnamp高性能架构之apache和nginx的整合

自此 LAMP 环境整合并搭建成功,那如何使用 Nginx 来整合 LAMP 呢?

lnamp高性能架构之apache和nginx的整合

源码安装 Nginx+LAMP 整合
先修改 apache 访问端口为 8080,Nginx 端口为 80。
然后修改 nginx 配置文件: vi /usr/local/nginx/conf/nginx.conf,server 配置段内容如
下(把nginx的发布目录指向apache的发布目录)
(定义 upstream 均衡模块,配置动静分离,动态转发至 apache,静态文件直接本地响应)
upstream app_lamp {
server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location / {
root /usr/local/apache/htdocs;
index index.php index.html index.htm;

location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://app_lamp;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /usr/local/apache/htdocs;
expires 3d;
}
}
测试,访问 nginx ip+port 如下图所示:

lnamp高性能架构之apache和nginx的整合

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774