nginx(七)-- Nginx WEB架构

  1. 动态网站架构
  2. LNMP动态网站环境部署

1.动态网站架构

        1.1资源

资源文件识别          语言识别               框架识别
index.php               开源的php        Windows/Linux+nginx+php+mysql
index.py                 开源python       Windows/Linux+apache+python+mysql
index.jsp                 商业JAVA         Windows/Linux+tomcat+JDK+Oracle
index.asp                商业c#             Windows+iis+asp.net+sql-server/oracle/mogodb

2.LNMP动态网站环境部署

        2.1LINUX部署

        关闭防火墙

        2.2Nginx部署

        安装nginx

        2.3php-fpm部署

        (一)部署方法一:RPM部署

yum install -y php-fpm php-mysql php-gd

php-fpm:php接收动态请求的程序
php-mysql:php链接mysql的程序
php-gd:图形库程序(GD库可以处理图片,或者生成图片)

注意这里的安装的php-fpm 如果版本过低则测试不成功,可以在阿里巴巴开源镜像站中安装"remi"源,该源中包含最新版本PHP和MySQL包的Linux源

systemctl restart php-fpm         启动php-fpm

netstat -anpt | grep 9000          查看php-fpm的端口【php-fpm的端口为9000】

vim /usr/share/nginx/html/index.php         测试php页面(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;
}
}

什么是动态请求(index.php)将动态请求转发给九千岁(php-fpm)九千岁的位置

fastcgi_param:这个配置的意思是 在浏览器中访问的.php文件,实际读取的是 $document_root(网站根目录)下的.php文件 -- 也就是说当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不回去网站根目录下访问.php文件,所以返回空白

通过location指令,将所有以php为后缀的文件都交给127.0.0.1:9000来处理,而这里的IP地址和端口就是FastCGI进程监听的IP地址和端口。
fastcgi_param指令指定放置PHP动态程序的主目录,也就是$fastcgi_script_name前面指定的路径,这里是/usr/local/nginx/html目录,建议将这个目录与Nginx虚拟主机指定的根目录保持一致,当然也可以不一致。
fastcgi_params文件是FastCGI进程的一个参数配置文件,在安装Nginx后,会默认生成一个这样的文件,这里通过include指令将FastCGI参数配置文件包含了进来。
接下来,启动nginx服务。
/usr/local/nginx/sbin/nginx
到此为止,Nginx+PHP已经配置完成。

        重启nginx服务并访问:http://192.168.26.147/index.php

         (二)部署方法二(源码部署)

部署PHP-fpm
1. 以php-fpm的方式安装php
[root@tianyun ~]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \
libxml2 libxml2-devel libcurl libcurl-devel libxslt-devel openssl-devel

[root@webserver ~]# tar xf php-5.6.29.tar.xz 
[root@webserver ~]# cd php-5.6.29/
[root@webserver ~]# ./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-jpeg-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
[root@webserver php-5.6.29]# make
[root@webserver php-5.6.29]# make install

2. php-fpm配置文件(影响php处理php程序的性能,例如php进程数、最大连接数配置等,运维人员关注)
[root@webserver php-5.6.29]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

3. php置文件(影响php代码,例如允许客户端最大上传文件的大小,设置的timezone,php所支持的扩展功能例如是否可以连接MySQL、Memcache,程序员关注)
[root@webserver php-5.6.29]# cp php.ini-production /usr/local/php/lib/php.ini

4. init script centos6 [可选]centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 c
[root@webserver php-5.6.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@webserver php-5.6.29]# chmod a+x /etc/rc.d/init.d/php-fpm
[root@webserver php-5.6.29]# chkconfig --add php-fpm
[root@webserver php-5.6.29]# chkconfig php-fpm on
[root@webserver php-5.6.29]# service php-fpm start
Starting php-fpm  done

4. Systemd Script centos7 [可选]
[root@webserver ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

[root@webserver ~]# systemctl start php-fpm.service 
[root@webserver ~]# systemctl status php-fpm.service


[root@localhost ~]# ss -an |egrep ':80|:9000'
tcp    LISTEN     0      128    127.0.0.1:9000                  *:*                  
tcp    LISTEN     0      128                  *:80                  *:*  

        (三)自学站点:

PHP 教程

        2.4mysql 部署

        (一)部署方法一(RPM部署)

yum -y install mariadb-server mariadb          安装mysql服务器程序和客户机程序。

systemctl start mariadb                 启动mysql服务器

systemctl enable mariadb            开机启动mysql服务器

mysqladmin password '123456'       修改mysql的root密码为‘123456’

create database bbs;               准备数据库,存放app

 grant all on bbs.* to phptest@'192.168.100.10' identified by '123456'; 

    授权phptest用户管理bbs库

flush privileges;               刷新权限

vim /usr/share/nginx/html/index.php         

<?php
$servername = "192.168.26.147";
$username = "phptest";
$passwd = "123456";

$conn = mysqli_connect($servername,$username,$passwd);

if(!$conn){
    die("connection failed:" . mysqli_connect_errno());
}else{
    echo "成功连接数据库";
    mysqli_close($conn);

}
?>

修改主页,测试MYSQL的链接状态

如果测试为faile,请检查数据库授权结果。

        (二)部署方法二(源码部署)略

        2.5业务上线

        (一)下载wordpress

官网地址:适用于博客到大型网站的 CMS (内容管理系统) | WordPress.org China 简体中文

下载wordpress包:wget  https://cn.wordpress.org/latest-zh_CN.tar.gz

 解压wordpress: tar  -xf   ./latest-zh_CN.tar.gz

清除之前的index.php  :rm -rf /usr/share/nginx/html/index.php

将解压之后wordpress目录下的文件拷到nginx网站的根目录下:

cp -rf  /root/wordpress/* /usr/share/nginx/html

更改nginx网站根目录的属主:

chown -R nginx.nginx /usr/share/nginx/html/*

更改网站的权限:chmod 777 /usr/share/nginx/html/

再用客户端去访问nginx:192.168.26.147

填写信息:数据库名称   数据库用户   数据密码    必须和前方授权一致。

如果出现wp-config.php文件不可写。请手动创建。    vim /usr/local/nginx/html/wp-config.php

 

 填写密码等信息:

v6PNs2m$68wMgotY5y

 

 

 

 

        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx是一种高性能的Web服务器和反向代理服务器软件,可以在Linux、Windows、UNIX等操作系统上运行。它以其稳定性、高并发性和低内存消耗而受到广泛关注和使用。 nginx 1.18是nginx的一个版本,其中包含了一系列的新特性和改进。这个版本引入了新的HTTP/2服务器推送功能,提供了更好的性能和可扩展性。同时,该版本还增加了对TLS 1.3的支持,加强了传输层安全性。此外,nginx 1.18还改进了负载均衡算法,提高了对后端服务器的请求分发效率。总之,nginx 1.18在性能、安全性和功能上都有所提升,是一个值得使用的版本。 nginx-mod-stream是一个nginx模块,用于处理TCP/UDP流量。它提供了一系列的功能,如四层(网络层)和层(应用层)的负载均衡、流量分片、数据重定向等。通过使用nginx-mod-stream,我们可以在一个单独的nginx服务器上同时处理HTTP和TCP/UDP流量,增加了服务器的灵活性和可扩展性。 通过将nginx 1.18和nginx-mod-stream结合使用,我们可以构建一个强大的、高性能的网络架构nginx 1.18提供了优秀的HTTP服务和反向代理能力,而nginx-mod-stream则提供了处理TCP/UDP流量的功能。这样可以让我们的应用程序更加灵活,在一个服务器上同时处理不同类型的流量,提高服务器的利用率和性能。因此,nginx 1.18和nginx-mod-stream是两个重要的组件,能够帮助我们构建高效的网络架构

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值