LNMP(linux,nginx,mariadb,php)
静态网页(用户要什么,服务器就找什么,并直接返回给客户)
动态网页(用户要页面,服务器识别是脚本,在服务器执行脚本,把结果返回给用户)
部署环境
~首先安装好nginx
yum -y install mariadb mariadb-server mariadb-devel //分别为数据库程序 数据库服务器--存放数据 数据库依赖包
yum -y install php php-mysql //php程序语言---------连接数据库 php为编程语言解释器 php-mysql扩展模块
<?php php解释器
$i=33;
echo $i; 命令结尾都需要有 ; 号
?> 结尾
yum -y install php-fpm //自动编译php语言
nginx //80端口
php-fpm //9000端口
mariadb-server //3306端口
动静分离
判断,如果是静态页面则nginx直接返回页面
如果是动态页面,则nginx先转发给(9000端口php)。php执行脚本,返回给nginx,nginx返回结果给用户。
location 可以匹配用户的地址栏 支持正则
location ~ \.php$ {
root html;
转发给9000;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
nginx日志 /usr/local/nginx/logs/error.log
php日志 /var/log/php-fpm/www-error.log
未做动静分离时访问页面会出现下载界面
未启服务会出现(nginx,php-fpm) an error /var/log/php-fpm/www-error.log
php代码错误会出现空白界面 /var/log/php-fpm/www-error.log
N(web服务器)接收用户的请求
P(解释器)执行代码,解释代码
Mysql(数据库)读写数据
php-mysql php连接数据库用的扩展模块
前端开发:html css+div javascript html5(可以加入很多动画效果)
后端开发:php java python perl c
shell 仅限应用于运维 php是网页开发做的最好的语言
地址栏重写
location / {
root html;
index index.html index.htm;
rewrite /a.html /b.html redirect; //访问a.html会被转发去访问b.html
}
rewrite ^/ http://www.tmooc.cn;
//扩展为 rewrite ^/(.*) http://www.tmooc.cn/$1; //复制 / 后面的所有子目录到跳转网页后粘贴,$1代表第一个复制的参数 $2代表第二个被复制的参数以此类推。
location / {
root html;
index index.html index.htm;
}
$http_user_agent //这个变量可以看到用户使用的操作系统及版本,以及浏览器及版本
if ($http_user_agent ~* curl){ rewrite ^(.*)$ /curl/$1; //^(.*)$ 任意开头或结尾
} //~是正则表达式匹配‘包含xxx’ * 在这里的作用是可以使后面的参数不用区分大小写。
rewrite 旧地址 新地址 [选项];
last 不再读其他rewrite
break 不再读其他语句,结束请求
redirect 临时重定向
permament 永久重定向
netstat 选项
-a--all : 显示所有连线中的socket ;
-n--numeric : 直接使用ip地质,而不是通过域名服务器 ;
-t--tcp : 显示TCP传输协议的连线状况 ;
-u--udp : 显示UDP传输协议的连线状况 ;
-p--programs :显示正在使用socket的程序识别码和程序名称 ;
-l--listening : 显示监控中的服务器的secket :