静态数据:

图片、GIF、视频

动态数据:

脚本、代码、java、PHP、python、Perl
默认不支持处理动态数据

主流的企业网站平台之一

— L:Linux操作系统
— N:Nginx网站服务软件
— M:MySQL、MariaDB数据库
— P:网站开发语言(PHP、Perl、Python)

部署LNMP环境

安装软件包

  1. 1. l**nginx**
  2. 1. l**mariadb**
  3. 1. l**mariadb-server**
  4. 1. l**mariadb-devel**
  5. 1. l**php**
  6. 1. l**php-fpm**
  7. 1. l**php-mysql**
l[root@server ~]# yum -y install mariadbmariadb-server mariadb-devel php php-mysql  php-fpm

启动mariadb

启动数据库服务
启动mariadb

[root@servernginx]# systemctl start mariadb

查看状态

[root@servernginx]# systemctl status mariadb

设置开机自启

[root@servernginx]# systemctl enable mariadb

启动php-fpm

启动php-fpm

[root@servernginx]# systemctl start php-fpm

查看状态

[root@servernginx]# systemctl status php-fpm

设置开机自启

[root@servernginx]# systemctl enable php-fpm

配置Nginx

拷贝Nginx备份文件覆盖主配置文件

[root@client conf]# cp nginx.conf.default   nginx.conf  
cp:是否覆盖"nginx.conf"? yes

重新加载服务

[root@client conf]# nginx -s reload

访问测试

组件LNMP平台

修改Nginx配置文件,设置Nginx连接php

 修改Nginx配置文件,设置Nginx连接php
location ~ \.php$ {  //匹配用户地址栏
            root           html;  //网页根目录
           fastcgi_pass   127.0.0.1:9000;  //php端口
           fastcgi_index  index.php;  //php默认首页
       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;  //调用fastcgi.conf文件
       }


重启服务:/usr/local/nginx/sbin/nginx –s reload

访问php测试

编写php测试脚本
[root@server html]# vim test.php     
<?php
$i=hello;
echo $i;
?>

浏览器访问测试:192.168.0.12/test.php

PHP连接数据库

 编写PHP脚本连接数据库,脚本参考 lnmp_soft/php_scripts/mysql.php


<?php
$mysqli = new mysqli(‘localhost’,‘root’,‘密码’,‘mysql’);     
解释:localhost为数据库域名或IP,root为mysql账户名,密码须修改为实际密码,默认为空密码    
if (mysqli_connect_errno()){
        die('Unable to connect!'). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
        printf("Host:%s",$row[0]);
        printf("</br>");
        printf("Name:%s",$row[1]);
        printf("</br>");
}
?>


访问测试:192.168.0.x/mysql.php

Nginx地址重写

什么是地址从写?

获取一个来访的URL请求,然后改成服务器可以处理的另一个URL的过程

地址重写的好处

l缩短URL,隐藏实际路径提高安全性
l易于用户记忆
l易于被搜索引擎记录

Nginx地址重写语法

lrewrite 基于语句
lrewrite regex replacement flag
lrewirte就地址 新地址 [选项]
l选项:
lredirect 临时重定向
lpermament 永久重定向
l应用案例:要求访问 a.html -à b.html
lrewrite /a.html /b.html;

地址重写应用案例

l应用案例:要求访问 a.html -à b.html

[root@client ~]# vim /usr/local/nginx/conf/nginx.conf

server {
listen       80;
server_name  localhost;
location / {
root   html;
index  index.html index.htm;
rewrite /a.html /b.html redirect;
}

[root@client ~]# nginx -s reload  //重启服务

l访问测试:192.168.0.x/a.html

域名跳转

案例要求:访问192.168.0.x 跳转到www.baidu.com

[root@client ~]# vim /usr/local/nginx/conf/nginx.conf

server {
listen       80;
server_name  localhost;
rewrite ^/ http://www.baidu.com;
解释:当有人访问以根开始,跳转到www.baidu.com

重新加载服务
[root@client ~]# nginx -s reload

访问测试:192.168.0.x/xxxx

案例要求:当访问本网站下的子页面时,跳转到www.baidu.com下相同的子页面

[root@client ~]# vim /usr/local/nginx/conf/nginx.conf


server {
listen       80;
server_name  localhost;
rewrite   ^/(.*)    http://www.baidu.com/$1;

重新加载服务
[root@client ~]# nginx -s reload

访问测试:192.168.0.x/xxxx