LNMP(动态网站)

LNMP(动态网站)
nginx(静态网站)

案例1:部署LNMP环境
步骤一:安装软件
yum -y install mariadb mariadb-server
yum -y install mariadb-devel
yum -y install php php-mysql
cd lnmp_soft
rpm -ivh php-fpm-5.4.16-36.el7_1.x86_64.rpm

启动服务
nginx
systemctl start php-fpm
systemctl start mariadb

LNMP

nginx----PHP(动静分离)
nginx判断用户访问的是静态还是动态
如果是静态,则在root对应的目录中找到页面直接给用户
如果是动态,则nginx将请求转发给9000端口
location匹配用户的地址栏(支持正则)
eg server {
listen 80;
server_name localhost;
location / {
root html;
}
location ~ .php$ {
pass 127.0.0.1:9000;
}
}
案例2:构建LNMP平台
vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
/usr/local/nginx/sbin/nginx -s reload

创建PHP页面,测试LNMP架构能否解析PHP页面

1)创建PHP测试页面1:
[root@svr5 ~]# vim /usr/local/nginx/html/test1.php
<?php
$i="This is a test Page";
echo $i;
?>

http://192.168.4.5/test1.php
常见错误
File not found:没有权限
ls,权限【rwx,selinux,acl】
Connection refused:PHP没有启动
PHP Parse error:syntax error
PHP语法错误
location 下载页面

拷贝mysql模板
cd /root/lnmp_soft/php_scripts/
ls
cp mysql.php /usr/local/nginx/html/

地址重写
www.360buy.com ----> www.jd.com
格式:rewrite 旧地址 新地址 【选项】
last [地址变,不读其他rewrite]
break [地址变,不读其他语句,访问结束]
redirect [地址变]临时重定向
permament [地址变]永久重定向
支持正则
rewrite /a.html /b.html redirect;

修改Nginx服务配置
vim /usr/local/nginx/conf/nginx.conf
root html;
index index.html index.htm;(增加此行)
}
echo "B是大写的B" > /usr/local/nginx/html/b.html
访问192.168.4.5/a.html

rewrite ^/ http://www.tmooc.cn/;

使用uc访问是窄屏页面
使用ie访问是宽屏页面
mkdir /usr/local/nginx/htmlcurl
建立2个名字相同的网页
vim /usr/local/nginx/html/test.html
vim /usr/local/nginx/html/curl/test.html

vim /usr/local/nginx/conf/nginx.conf

if ($http_user_agent ~ curl){ //识别客户端curl浏览器
rewrite ^(.
)$ /curl/$1;
}
#发现包含curl的就访问curl/
nginx -s reload
验证
curl http://192.168.4.5/test.html
firefox http://192.168.4.5/test.html

转载于:https://blog.51cto.com/13402239/2051816

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值