CC00006.NGINX——|Nginx&Nginx.V1.16&企业级LNMP&Yum.V2|...

一、从0开始构建LNMP WEB平台,主要有两种方式;
### --- 从0开始构建LNMP WEB平台,主要有两种方式;

~~~     YUM二进制方式
~~~     MAKE源码编译方式
~~~     此处我们基于YUM二进制方式(网络源的形式,服务器能够上外网,配置局域网YUM源)
~~~     构建LNMP的操作
一、部署nginx:
### --- 添加Epel-release扩展源

[root@localhost ~]# yum -y install epel-release 
[root@localhost ~]# ll /etc/yum.repos.d/|grep -aw epel
-rw-r--r-- 1 root root  951 Oct  3  2017 epel.repo
-rw-r--r-- 1 root root 1050 Oct  3  2017 epel-testing.repo
### --- 安装nginx软件包:
### --- 显示Complete!表示安装成功;

[root@localhost ~]# yum -y install nginx
### --- 检测nginx软件包是否安装成功

[root@27ba4cba71d5 ~]# rpm -qa |grep nginx 
nginx-filesystem-1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-perl-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-mail-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-all-modules-1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-xslt-filter-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-stream-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-image-filter-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
### --- 查看端口和进程

[root@27ba4cba71d5 ~]# systemctl start nginx.service
[root@27ba4cba71d5 ~]# ps -ef |grep nginx 
[root@27ba4cba71d5 ~]# netstat -tunlp |grep -aw 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      258/nginx: master p 
tcp6       0      0 :::80                   :::*                    LISTEN      258/nginx: master p
二、部署Mariadb:
### --- 安装Mariadb:

[root@27ba4cba71d5 ~]# yum -y install mariadb-server mariadb mariadb-devel
### --- 检测Mariadb安装是否成功:

rpm -qa |grep mariadb
### --- 查看Mariadb进程和端口号;

[root@27ba4cba71d5 ~]# systemctl start mariadb.service
[root@27ba4cba71d5 ~]# ps -ef |grep mysql
mysql        452       1  0 08:04 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr
root         518     121  0 08:04 ?        00:00:00 grep --color=auto mysql
[root@27ba4cba71d5 ~]# netstat -tunlp |grep -aw 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      452/mysqld
三、部署PHP:
### --- 安装php

[root@27ba4cba71d5 ~]# yum -y install php php-devel php-fpm php-mysql
### --- 检测PHP是否安装成功:

[root@27ba4cba71d5 ~]# rpm -qa |grep php
### --- 查看PHP进程及端口号
### --- 此时没有查到9000端口

[root@27ba4cba71d5 ~]# systemctl start php-fpm.service
[root@27ba4cba71d5 ~]# ps -ef |grep php
[root@27ba4cba71d5 ~]# netstat -tunlp|grep -aw 9000
四、根据如上LNMP部署指令操作,LNMP平台部署完成,查看其进程
### --- 根据如上LNMP部署指令操作,LNMP平台部署完成,查看其进程

[root@27ba4cba71d5 ~]# ps -ef |grep -wE "nginx|mysqld|php"
root         258       1  0 07:52 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx        259     258  0 07:52 ?        00:00:00 nginx: worker process
nginx        260     258  0 07:52 ?        00:00:00 nginx: worker process
mysql        452       1  0 08:04 ?        00:00:03 /usr/libexec/mysqld --basedir=/usr
root         598       1  0 08:14 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
apache       599     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       600     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       601     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       602     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       603     598  0 08:14 ?        00:00:00 php-fpm: pool www
root         647     121  0 08:23 ?        00:00:00 grep --color=auto -wE nginx|mysqld|php
五、nginx和php-fpm进行配置整合
### --- 要讲nginx和php-fpm进行配置整合,实现nginx检测到用户请求PHP动态网页时,
### --- nginx会将用户的请求通过CGI网关协议发送给后端PHP-FPM解释器取出来,
### --- nginx.conf配置代码如下:

### --- nginx配置:
[root@localhost nginx]# 
        location / {                                            // 第二步
            root   html;
            index index.php index.html index.htm;               // 加上nginx.php表示引导页。

        location ~ \.php$ {
            root           /usr/share/nginx/html;               // 更改发布目录;第一步
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;                           // 添加$document_root;表示发布目录  //第三步
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
### --- 查看nginx.conf文件并去掉#号空行。

[root@localhost nginx]# grep -vE "#|^$" nginx.conf
worker_processes  1;                    
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;                                      // 以上为全局配置
    server {                                                    // 以下为server主机的配置
        listen       80;
        server_name  localhost;
        location / {                                            // location /是正常匹配,处于正则匹配后执行。
            root   html;
            index index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {                                     // location ~是正则匹配,是优先匹配,   
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;                           // 指定发布目录的变量,绝对路径也可以:/usr/share/nginx/html;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;   
            include        fastcgi_params;
        }
    }
}
六、更改完成之后:
### --- 重启nginx服务

[root@27ba4cba71d5 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@27ba4cba71d5 nginx]# nginx -s reload
七、nginx、php-fpm发布目录;/usr/share/nginx/html,在该目录创建index.php,代码内容如下。
### --- nginx、php-fpm发布目录;
### --- /usr/share/nginx/html,在该目录创建index.php,代码内容如下。

[root@27ba4cba71d5 nginx]# vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
八、通过LNMP发布网站:
### --- 我们只需要把我们打开发包解压到发布目录就可以了:

[root@localhost ~]# ls
anaconda-ks.cfg  web.html.tar
[root@localhost ~]# tar -zxvf web.html.tar /usr/share/nginx/html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值