LNMP简要配置

pre.ctl { font-family: "Liberation Mono", monospace }
p { margin-bottom: 0.25cm; line-height: 120% }
a:link { }

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



工作流程:
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
[[email protected] ~]# grep -v "^;" /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000                监听9000(php-fpm服务)
listen.allowed_clients = 127.0.0.1        允许的客户地址
user = apache                    用户
group = apache                    用户组
pm = dynamic                    模式
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
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:9000

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            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 80
            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 80
            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/$1;
    }
#cd  /usr/local/nginx/html
#echo "1" >test.html
#mkdir curl
#echo "2" >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、空白页面 脚本写错了

时间: 2024-08-13 09:41:13

LNMP简要配置的相关文章

CenOS 6 DNS服务器简要配置

yum install bind* 一.修改下面配置文件 vi /etc/named.conf options { listen-on port 53 { 192.168.100.210; }; listen-on-v6 port 53 { ::1; }; directory       "/var/named"; dump-file       "/var/named/data/cache_dump.db"; statistics-file "/var/

ARUBA IAP简要配置指导

ARUBA IAP简要配置指导 一.     基本配置 1.      首先启动IAP,将两颗(或者多颗如学校部署多个AP)IAP接在同一个网段里,AP启动后使用笔记本无线功能搜索名称为instant的SSID.搜到后点击连接该SSID.如下图: 2.      无线连上instant的SSID之后查看PC是否获取到非169.x.x.x网段的地址,查看结果如下: 3.      打开网页输入https://instant.arubanetworks.com(有可能浏览器会提示此网站证书不受信任,

lnmp 后续配置

1.添加虚拟主机,执行如下命令:/root/vhost.sh 根据提示输入要绑定的域名,回车,如果需要添加更多的域名,输入y,再输入要另外绑定的域名,多个域名可以用空格隔开(注:带www和不带www的是不同的域名,如需带www和不带的www的域名都访问同一个网站需要同时都绑定).再输入域名绑定的目录(绝对目录,如/home/wwwroot/lnmp,如果不填默认是/home/wwwroot/绑定的域名,目录不一定非要是/home/wwwroot/,如果/data/ 下面有大量的空间也可以填写/d

lnmp 安装配置--libmcrypt问题

在LNMP安装配置中,在进行php配置依赖包时遇到如何错误 wget  http://cn2.php.net/distributions/php-5.4.37.tar.bz2tar jxf php-5.4.37.tar.bz2useradd -s /sbin/nologin php-fpm cd php-5.4.37 useradd -s /sbin/nologin php-fpm php依赖包参看lamp php安装 ./configure --prefix=/usr/local/php   

Window下同一台服务器部署多个MariaDB(Mysql)、服务方式启动简要配置

版本:MariaDB 10 环境:D盘下,放2个MariaDB解压版,分别是D:\MariaDB.D:\MariaDBA 1.进入MariaDB.MariaDBA,复制my-XXX.ini(不同的文件对应不同的硬件配置),改名为my.ini 2.文本编辑器打开D:\MariaDBA的my.ini,修改把2个涉及端口的地方,避免与MariaDB的冲突 3.注册服务,进入D:\MariaDB\bin,命令运行"mysqld.exe --install MariaDB10",进入D:\Mar

Zabbix&LNMP安装配置

监控端操作 #!/bin/bash #安装zabbix+LNMP # lnmp(){ #关闭防火墙&核心安全功能 systemctl stop firewalld.service systemctl disable firewalld.service &> /dev/null setenforce 0 sed -i "7cSELINUX=disabled" /etc/sysconfig/selinux #yum安装nginx wget http://nginx.o

LNMP环境配置

LNMP=Linux+Nginx+Mysql+PHP Install Nginx //安装依赖包 # yum install openssl openssl-devel zlib-devel //安装pcre # wget http://exim.mirror.fr/pcre/pcre-8.01.tar.gz # tar xf pcre-8.01.tar.gz -C /usr/local/web/ # cd /usr/local/web/pcre-8.01/ # ./configure # ma

lnmp安装配置

一.总体简介 Lnmp架构(Linux+nginx+mysql+php)是目前网站的主流架构,这个架构包含了一个网站的最基本要求:运行环境+web容器+动态页面处理+存储.当然同样主流的架构还有lamp,但是个人认为nginx的性能在现在的趋势下更胜一筹. 二.Nginx优势 Nginx是一款高性能的web服务器.反向代理服务器.负载均衡服务器,它的高性能主要体现在它引入了基于事件驱动的I/O模型,支持高并发,并且占用内存资源少.作为web服务器,nginx比apache使用更少的资源,支持更多

VM虚拟机 Centos7 lnmp环境 配置域名问题 windows浏览器访问的问题

CentOS7  ip地址为 192.168.0.155 搭有 LNMP集成环境 执行 lnmp vhost add 配置服务器 指定目录的域名 mark.com 这时windows 机器的 浏览器想要访问 mark.com 需要在 C:\Windows\System32\drivers\etc 下的hosts 文件需要加一行 192.168.0.155 mark.com