LNMP简要配置

部署LNMP环境
nginx[web服务,接收用户的请求]
php [解释器]
yum -y localinstall php-fpm-5.4.<tab> [服务]
mariadb [数据库客户端]
mariadb-server [数据库服务器]
mariadb-devel [依赖包]
php-mysql [php连接mysql的扩展包]
所有服务
[root@proxy lnmp_soft]# netstat -nutlp |grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master
[root@proxy lnmp_soft]# netstat -nutlp |grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
[root@proxy lnmp_soft]# systemctl restart php-fpm
[root@proxy lnmp_soft]# netstat -nutlp |grep
tcp 127.0.0.1: 0.0.0.0:* LISTEN /php-fpm: mast
nginx+FastCGI
工作原理图:

LNMP简要配置

工作流程:
1、web server 启动时载入fastCGI进程管理器
2、FastCGI进程管理器初始化,启动多个解释器进程
3、当客户端请求到达web server时,FastCGI进程管理器选择并连接一个解释器(php 9000)
4、FastCGI子进程完成处理后返回结果,将标准输出和错误信息从同一连返回web server FastCGI简介
FastCGI是一种常住型的CGI
将CGI解释器进程保持在内存中,进行委会与调度
FastCGI技术目前支持语言有PHP、C/C++、jave、Perl、Python、Ruby等
FastCGI缺点:内存消耗大
配置FastCGI
[root@proxy ~]# grep -v "^;" /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1: 监听9000(php-fpm服务)
listen.allowed_clients = 127.0.0.1 允许的客户地址
user = apache 用户
group = apache 用户组
pm = dynamic 模式
pm.max_children =
pm.start_servers =
pm.min_spare_servers =
pm.max_spare_servers =
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
编辑nginx.conf
location ~ \.php$ {
proxy_pass http://127.0.0.1;
} pass the PHP scripts to FastCGI server listening on 127.0.0.1: location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
地址重写
rewrite 旧 新 【选项】
redirect 地址栏变,临时重定向
permanent 地址栏变,永久重定向
last 停止执行其他rewrite
break 停止执行其他语句,结束访问
rewrite /a.html /b.html last;
rewrite /b.html /c.html last;
rewrite /c.html /a.html last; 防止死循环 1:访问a.html跳转到b.html
vim /usr/local/nginx/conf/nginx.conf
... ...
server {
listen
server_name localhost;
location / {
rewrite a.html /b.html redirect;
}
#echo "BB" > /usr/local/nginx/html/b.html
#nginx -s reload
2:访问192.168.4.5跳转到www.tmooc.cn
vim /usr/local/nginx/conf/nginx.conf
... ...
server {
listen
server_name localhost;
location / {
rewrite ^/ http://www.tmooc.cn;
} 附加:
访问旧的网站页面,跳转到新的网站相同页面
rewrite ^/(.*) http://www.jd.com/$1;
保留和粘贴
3:不同浏览器访问相同页面返回结果不同
ie  http://192.168.4.5/test.html 

firefox http://192.168.4.5/test.html

uc  http://192.168.4.5/test.html

nginx【内置变量】
vim /usr/local/nginx/conf/nginx.conf
server {
... ...
if ($http_user_agent ~* curl){
rewrite ^/(.*) /curl/$;
}
#cd /usr/local/nginx/html
#echo "" >test.html
#mkdir curl
#echo "" >curl/test.html
#nginx -s reload
firefox http://192.168.4.5/test.html
curl http://192.168.4.5/test.html
4:如果用户访问的页面不存则转到首页
vim /usr/local/nginx/conf/nginx.conf
server {
... ...
if (!-e $request_filename){
rewrite ^/ http://192.168.4.5;
}
#nginx -s reload

易错

1、php服务没有启动

2、nginx配置文件[动静分离] 出现下载页面

3、404 not found 没有此网页或网页位置放错

4、空白页面 脚本写错了

上一篇:Python UDP和TCP套接字简单创建和连接


下一篇:Python的循环导入问题