#####################

---LNMP
企业主流的网站平台
L --> Linux系统
N --> Nginx网站服务软件
M --> Mariadb数据库
P --> Php网站开发语言

#####################

---LNMP环境搭建

(1)安装Nginx 端口:80 nginx软件包不在光盘内,需源码包编译安装

安装依赖软件包 yum -y install gcc openssl-devel(支持https) pcre-devel(支持正则表达式)

tar xf nginx-1.8.0.... cd nginx-1.8.0 ./configure \

--prefix=/usr/local/nginx \ //指定安装目录 --with-http_ssl_module //增加安全模块 make //编译 make install //安装

ln -s /usr/local/nginx/sbin/nginx /usr/sbin //制作快捷方式 ls /usr/local/nginx logs :日至文件 sbin :程序文件 conf :配置文件 html :网页文件

nginx //启动服务 nginx -s stop //停止服务 nginx -s reload //重新加载配置文件 nginx -V //查看nginx信息

#####################################

安装php软件包 端口:9000

yum -y install php php-mysql(实现php与数据库连接) rpm -ivh php-fpm....

/etc/php-fpm/www ####################################

安装mariadb软件包 端口:3306 yum -y install mariadb mariadb-server mariadb-devel

###################################

启动LNMP 环境 nginx systemctl restart mariadb systemctl restart php-fpm

##################################

---制作动静分离页面

【LNMP】
vim test.php
<?php
$i=33;
$j=44'
echo $i;
?>

php test.php
33

mv test.php /usr/local/nginx/html

【客户端】

firefox 192.168.4.5/test.php
                  //需要下载,并且看到的只是源代码
                  //这是所谓的静态页面

所谓的动态页面,即把源代码经过解释后,显示到屏幕上的内容

为了让客户端能够读到静态页面和动态页面,需要在nginx上进行区分
【LNMP】
/usr/local/nginx/conf/nginx.conf
http {
   server {
    	listen 80;
    	server_name localhost;
    	location / {
     		root html
     		index index.html index.htm;      //对应静态页面   
	}
  
    	location ~\.php$ {
    		root html
    		fasticgi_pass 127.0.0.1:9000;
    		fasticgi_index index.php;
    	     #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 
    		include        fastcgi.conf;            //对应动态页面 
    	}
     }
}

nginx -s reload 

【客户端】

firefox 192.168.4.5/test.php
33

File not found. 出现这个 表示selinux 限制 test.php 没有安全上下文(标签)selinux 改成premissive
##########################################

	---地址重写
	
意义: 换ip地址后,对于一些用户将无法访问,使用地址重写,即把访问老地址 转换成新地址
   如:访问 www.360.com -->www.so.com
   
   (1)访问此网站的内容跳转到新的内容
【LNMP】   
   http {
   	server {
   		listen 80;
   		server_name localhost;
   		
   		location / {
   			root html
   			index index.html
   			rewrite /a\.html /b\.html      //因为支持正则,.代表匹配任意单个字符,所以屏蔽特殊字符
   		}
   	}
   }
   
   echo "aaaa" > /usr/local/nginx/html/a.html
   echo "bbbb" > /usr/local/nginx/html/b.html
   
【客户端】

firefox 192.168.4.5/a.html
bbbb

(2)访问此网站跳转到别的网站

http {
   	server {
   		listen 80;
   		server_name localhost;
   		rewrite ^/(.*)  http://www.tmooc.cn/$1;  // 匹配到 / 时 跳转到 http://www.tmooc.cn/ 网站中
   		                                                // (.*)是把/后面的保存起来  $1粘贴  正则中为 \1
   		location / {
   			root html;
   			index index.html;
   			#rewrite /a\.html /b\.html;   
   		}
   	}
   }

【客户端】
firefox 192.168.4.5/yyyy  ---> www.tmooc.cn/yyyy

(3)区分浏览器或者是不同设备   让电脑端(手机端)显示相同内容,格式不同

http {
   	server {
   		listen 80;
   		server_name localhost;
   		if ($http_user_agent ~* firefox) {         
   		rewrite ^/(.*) /firefox/$1;
   		}
   		//$http_user_agent 日至消息中的一段,其中包含firefox等浏览器信息,匹配到此浏览器后跳转到其网页中
   		
   		
   		#rewrite ^/(.*)  http://www.tmooc.cn/$1;  // 匹配到 / 时 跳转到 http://www.tmooc.cn/ 网站中
   		                                                // (.*)是把/后面的保存起来  $1粘贴  正则中为 \1
   		location / {
   			root html;
   			index index.html;
   			#rewrite /a\.html /b\.html;   
   		}
   	}
   }
	mkdir /usr/local/nginx/html/firefox
	echo "firefox" > /usr/local/nginx/html/firefox/test.html
	echo "chrome" > /usr/local/nginx/html/test.html
	
	【客户端】
	firefox 192.168.4.5/test.html  //使用火狐浏览器
	firefox
	curl 192.168.4.5/test.html   //使用curl 浏览器
	chrome
	
	在实际网站中  两个访问的内容相同,格式不同
###########################################################