部署LNMP

24 篇文章 0 订阅

LNMP安装

  • 安装nginx
  • 安装mariaDB
yum -y install mariadb-server
yum -y install mariadb
yum -y install mariadb-devel
  • 安装PHP
yum -y install php
yum -y install php-fpm
  • 安装PHP扩展
yum -y install php-mysql
  • 启动服务

注意:应该按照顺序安装,因为PHP需要使用apache和MySQL的相关信息

Nginx+FastCGI

FastCGI工作原理
graph LR
A(Internet)-->B(Nginx)
B-->C((socket))
C --> D(FastCGI)
C --> E(FastCGI)
C --> F(FastCGI)
D --- H[APP1]
E --- I[APP2]
F --- J[APP3]
FastCGI工作流程
  1. Web Server启动时载入FastCGI进程管理器
  2. FastCGI进程管理器初始化,启动多个解释器进程
  3. 当客户端请求到达Web Server时,FastCGI进程管理器选择并连接到一个解释器
  4. FastCGI子进程完成处理后返回结果,将标准输出和错误信息从同一连接返回给Web Server
FastCGI简介

FastCGI技术目前支持语言有PHP、C/C++、Java、Python、Ruby等

FastCGI缺点

内存消耗大,因为是多进程,所以比CGI多线程消耗更多的服务器内存,PHP-CGI解释器每进程消耗7-25m内存

配置FastCGI
# vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

user = apache
group = apache
pm.max_children = 50
pm.start_servers = 5
配置nginx
# 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; #php-fpm的IP与端口
    fastcgi_index index.php;
    include fastcgi.conf; #加载Fast-CGI参数文件
}

Nginx高级技术(地址重写)

基础知识
  • 什么是地址重写

    • 获得一个来访的URL请求,然后改写成服务器可以处理的另一个URL的过程
  • 地址重写的好处

    • 缩短URL,隐藏实际路径提高安全性

    • 易于用户记忆和键入

    • 易于被搜索引擎收录

rewrite语法
# 基本语句一
rewrite regex replacement flag
# 基本语句二
if(条件){...}
应用案例
  • 要求:a.html --> b.html
location / {
    root html;
    index index.html index.htm;
    rewite "/a.html$" /b.html;
}
  • 要求:域名跳转(www.tarena.com —> bbs.tarena.com)
server{
    listen 80;
    server_name www.tarenca.com;
    location / {
        root html;
        index index.html index.htm;
        rewrite ^/(.*) http://bbs.tarenca.com/$1;
    }
}
  • 要求:根据浏览器返回不同的页面
server{
    listen 80;
    server_name www.tarenca.com;
    location / {
        root html;
        index index.html index.htm;
    }
    if($http_user_agent ~firefox){
        rewrite ^(.*)$ /nginx-firefox/$1 break;
    }
}
正则表达式

正则表达式匹配模式如下:

  • 区分大小写匹配:~
  • 不区分大小写匹配:~*
  • 区分大小写不匹配:!~
  • 不区分大小写不匹配:!~*
rewrite选项

rewrite语句

  • rewrite regex replacement flag
  • flag:break、last、redirect、permanent
  • last:停止执行其他重写规则,根据URI继续搜索其他location,地址栏不改变
  • break:停止执行其他重写规则,完成本次请求
  • redirect:302临时重定向,地址栏改变,爬虫不更新URI
  • permanent:301永久重定向,地址栏改变,爬虫更新URI
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值