Nginx WEB架构实战篇(四)

本文详细介绍了LNMP动态网站部署过程,包括Linux环境配置、Nginx、php-fpm、MySQL的部署,以及业务上线。深入探讨了fastCGI和php-fpm的工作原理,讲解了php-fpm的初始化配置,如配置文件和子进程管理。此外,还涵盖了Nginx的Location和Rewrite规则,实现URL重定向和动态内容处理。最后讨论了私有CA和HTTPS的部署,以及Nginx的平滑升级策略。
摘要由CSDN通过智能技术生成

一、LNMP动态网站部署

1.1 Linux部署

stop firewalld
disable selinux
/etc/selinux/config

1.2 Nginx部署

yum install -y nginx

1.3 php-fpm部署

yum install -y php-fpm php-mysql php-gd    #如果报错$ yum install mariadb-embedded mariadb-libs mariadbbench 								mariadb mariadb-sever

systemctl restart php-fpm
systemctl enable php-fpm #开机启动


netstat -anpt   | grep 9000 #查看PHP端口号
vim /usr/share/nginx/html/index.php

#pnpinfo()调用PHP版本信息函数
<?php
phpinfo();
?>

vim /etc/nginx/conf.d/default.conf
#增加php主页 index.php
server {
   
location / {
   
...
index index.php index.html;
...
}
}

`vim /etc/nginx/conf.d/default.conf`
#启动nginx_fastcgi功能 


server {
   
location / {
   
index index.php;
}
location ~ \.php$ {
   
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

重启ngix

浏览器登录 192.168.238.132
在这里插入图片描述

1.4 mysql部署

RPM部署

yum -y install mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysqladmin password '123456'
create database bbs;
grant all on bbs.* to phptest@'192.168.100.10' identified by '123456';   #IP输入自己的IP地址
flush privileges;


vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.100.10','phptest','123456');
if (!$link)
              echo "Successfuly";
else
              echo "Faile";
mysql_close();
?>

浏览器测试 Successfuly

1.5 业务上线

wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip
unzip wordpress-4.9.1-zh_CN.zip
rm -rf /usr/share/nginx/html/index.php

cp -rf  /root/wordpress/* /usr/share/nginx/html
chown -R nginx.nginx /usr/share/nginx/html/*
chmod 777 /usr/share/nginx/html/
浏览器访问

如果出现wp-config.php文件不可写。请手动创建。

vim /usr/local/nginx/html/wp-config.php
#版本不同默认不同,如果没有	wp-config.php;默认文件是wp-config-sample.php
mv /usr/local/nginx/html/wp-config-sample.php  /usr/local/nginx/html/wp-config.php
vim /usr/loacl/nginx/html/wp-config.php  #修改mysql登录数据


***************
下面mysql数据库主机与编码版本不同设置不同
***************
我第二次尝试出错后更改了主机:localhost
编码:utf8

在这里插入图片描述
再访问浏览器

二、fastCGI & php-fpm

2.1 静态网站

nginx服务器能处理的是静态元素 .html .jpg .mp4 .css

2.2 nginx动态网站接口

ngx_fastcgi_modul 处理动态请求的接口 ## fastcgi 快速通用网关接口
fastCGI详解
nginx 通过ngx_fastcgi nginx 通过ngx_fastcgi_modul模块 链接 php-fpm处理动态请求。

2.3 php-fpm

PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)
是一个PHP FastCGI管理器。
PHP通过php-fpm接收前台nginx的动态访问的请求,比如向后端Mysql进行查询请求后

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值