作者:HE-KILL-MY-EGO | 来源:互联网 | 2023-10-17 13:52
LNMP架构的组成:Linux、Nginx、MySQL、PHP关于NginxNginx与apache的作用一样,都是为了搭建网站服务器,由俄罗斯人lgorsysoev开发,其特点是
LNMP架构的组成:
Linux、Nginx、MySQL、PHP
关于Nginx
Nginx与apache的作用一样,都是为了搭建网站服务器,由俄罗斯人lgor sysoev开发,其特点是占有内存少,并发能力强。
安装步骤:
1.安装Linux操作系统
2.安装Nginx服务
(1)安装支持软件



(2)创建运行用户、组

(3)解压所需软件包

(4)编译安装Nginx
启用http_stub_status_module模块以支持状态统计,便于查看服务器的连接信息。


(5)安装完成后的调整

(6)安装成功

在Nginx服务器的主要配置文件/usr/local/nginx/conf/nginx.conf中,包括全局配置、I/O事件配置和HTTP配置三大块内容,配置语句的格式为“关键字 值;”(末尾以分号表示结束),以“#”开始的部分表示注释。
Nginx服务器的两个基本应用
(1)Nginx的访问状态统计
Nginx内置了HTTP_STUB_STATUS状态统计模块,用来反馈当前的web访问情况,配置编译参数时可添加- -with-http_stub_status_module来启用此模块。
vim /usr/local/nginx/conf/nginx.conf


新的配置生效后,在浏览器中访问Nginx服务器的/status网站位置,可以看到当前的状态统计信息。其中,
“Active connections” 表示当前的活动连接数;
“service accepts handled requests”表示已经处理的连接信息,三个数字依次表示已经处理的连接数、成功的TCP握手次数、已处理的请求数

(2)基于域名的虚拟Web主机
使用Nginx搭建虚拟主机服务器时,每个虚拟Web站点拥有独立的"server { }"配置段,各自监听的IP地址、端口号可以单独指定,当然网站名称也是不同的。
(1)准备网站目录及测试文件

(2)搭建DNS服务器,进行域名解析;或者修改hosts文件

DNS 服务器指向自己,vim /etc/resolv.conf

(3)调整nginx.conf配置文件
配置两个“server { }”区域,分别对应两个Web站点,指定各自的网站名称、监听地址、网站根目录、访问日志等信息,然后重载配置。

修改网站名称和网站根目录


配置完成后,重启nginx服务
(4)访问虚拟Web主机


3.安装MySQL数据库
安装支持软件

编译安装cmake

编译安装MySQL


优化调整、初始化数据库

启动MySQL 服务

4.安装PHP解析环境
安装支持软件

编译安装PHP


安装后的调整

安装ZendGuardLoader


配置Nginx支持PHP环境
若要让Nginx能够解析PHP网页,有两种方法可以选择:其一,充当中介,将访问PHP页面的Web请求转交给其他服务器(LAMP)去处理;其二,通过使用PHP的FPM模块来调用本机的PHP环境。
(1)如果选用FPM方式,则需要先启动php-fpm进程,以便监听PHP解析请求。







(2)配置Nginx支持PHP解析
需要在“server { }”配置段中添加location设置,以便指定当访问.php网页时采取何种操作。
对于第一种方法(转交给其他web服务器处理)使用的配置语句如下
proxy_pass http://目标IP:80;
对于第二种方法(调用本机的php-fpm进程),使用的配置语句如下

(3)设置完成后重启服务,并编写一个测试网页



通过以上操作,LNMP平台就搭建成功了。
构建LNMP架构平台