四章——Nginx网站服务(应用——linux防护与群集)

news/2024/5/20 15:48:18/文章来源:https://blog.csdn.net/KW__jiaoq/article/details/119853382

三期总目录链接

目录

一、Nginx服务

1、安装及运行控制

2、配置文件nginx.conf

 2.1全局配置   解释:

 2.2  I/O事件配置   解释:

 2.3 HTTP配置    解释:

 3、访问状态统计及虚拟主机应用

二、LNMP架构及应用部署

 1、搭建LNMP网站平台

1.1、安装MYSQL数据库(三章———Mysql数据库系统3.1)

1.2、安装PHP解析环境

1.3配置nginx支持PHP环境

2、在LNMP平台中部署web应用

2.1部署程序代码

复习题


一、Nginx服务

Nginx (engine x) 是一款轻量级的HTTP服务器软件,优点:稳定性好、丰富的功能集、简单的配置文件和低系统资源的消耗,以及占有内存少,并发能力强(单台物理服务器可支持30000~50000个并发请求)正因如此,大量提供社交网络、新闻资讯、电子商务的企业纷纷选择 Nginx来提供服务    例:百度、京东、新浪、网易、腾讯、淘宝等

1、安装及运行控制

[root@C7--01 ~]# yum -y install pcre-devel zlib-devel       #安装支持软件  (提供相应的库 和头文件)
.........
....[root@C7--01 ~]# useradd -M -s /sbin/nologin nginx          #创建运行用户,组
[root@C7--01 ~]# tar xf nginx-1.12.0.tar.gz -C /usr/src/    #解压nginx
[root@C7--01 ~]# cd /usr/src/nginx-1.12.0/                  #进入目录
[root@C7--01 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
............
.....

安装目录设置为/usr/loca/nginx ,运行用户,组设置为nginx,启用  --with-http_stub_status_module   支持状态统计,便于查看服务器的连接信息

 问题:在进行解析安装时出现错误

[root@C7--01 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
checking for OS+ Linux 3.10.0-693.el7.x86_64 x86_64
checking for C compiler ... not found./configure: error: C compiler cc is not found

解决方法:安装 gcc  openssl-devel

[root@C7--01 nginx-1.12.0]# yum -y install gcc pcre-devel zlib-devel openssl-devel         

[root@C7--01 nginx-1.12.0]# make && make install     #编译安装[root@C7--01 nginx-1.12.0]# ls /usr/local/nginx/     #验证安装
conf  html  logs  sbin

优化执行(方便nginx 运行)

[root@C7--01 nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/    #软连接
[root@C7--01 nginx-1.12.0]# ls -l /usr/local/sbin/
总用量 0
lrwxrwxrwx 1 root root 27 8月  28 00:13 nginx -> /usr/local/nginx/sbin/nginx

查看nginx帮助命令 

[root@C7--01 ~]# nginx -h
nginx version: nginx/1.12.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:-?,-h         : this help-v            : show version and exit-V            : show version and configure options then exit-t            : test configuration and exit-T            : test configuration, dump it and exit-q            : suppress non-error messages during configuration testing-s signal     : send signal to a master process: stop, quit, reopen, reload-p prefix     : set prefix path (default: /usr/local/nginx/)-c filename   : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file

 1.1启动、停止

[root@C7--01 ~]# nginx       #启动nginx服务
[root@C7--01 ~]# netstat -utpln | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      44886/nginx: master 

 访问测试

 在字符界面可以使用文本浏览器查看

  -dump:将HTML文档以纯文本的方式打印到标准输出设备

[root@C7--01 ~]# yum  -y install elinks         #安装文本浏览器
[root@C7--01 ~]# elinks  --dump  http://192.168.1.1Welcome to nginx!If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.For online documentation and support please refer to [1]nginx.org.Commercial support is available at [2]nginx.com.Thank you for using nginx.ReferencesVisible links1. http://nginx.org/2. http://nginx.com/

 主程序Nginx支持标准的进程信号,通过kill或killall命令发送HUP信号表示重载配置,QUIT信号表示退出进程,KILL信号表示杀死进程,最小化安装的centos 系统默认没有安装killall命令,需要先安装

[root@C7--01 ~]# yum -y install psmisc          #安装killall命令
...........
.....[root@C7--01 ~]# killall -s HUP  nginx          # 重载配置 相当于  killall  -1  nginx
[root@C7--01 ~]# netstat -utpln | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      46095/nginx: master [root@C7--01 ~]# killall -s QUIT  nginx         # 停止服务  相当于 killall -3 nginx   (退出进程)
[root@C7--01 ~]# netstat -utpln | grep nginx

 编写nginx服务脚本使用 systemctl 工具进行管理

[root@C7--01 ~]# vi /etc/init.d/nginx#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Server Control Script
NP="/usr/local/nginx/sbin/nginx"
NPF="/usr/local/nginx/logs/nginx.pid"
case "$1" instart)$NP;if [ $? -eq 0 ]thenecho "nginx is starting!! "fi;;stop)kill -s QUIT $(cat $NPF)if [ $? -eq 0 ]thenecho "nginx is stopping!! "fi;;restart)$0 stop$0 start;;reload)kill -s HUP $(cat $NPF)if [ $? -eq 0 ]thenecho "nginx config file is reload! "fi;;*)echo "Usage: $0 {start|stop|restart|reload}"exit 1
esac
exit 0[root@C7--01 ~]# chmod +x /etc/init.d/nginx    #赋予执行权限
[root@C7--01 ~]# chkconfig --add nginx         #添加为系统服务
[root@C7--01 ~]# systemctl status nginx        #查看nginx 服务状态
● nginx.service - SYSV: Nginx Server Control ScriptLoaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)Active: inactive (dead)Docs: man:systemd-sysv-generator(8)

2、配置文件nginx.conf

     Nginx服务器主配置文件:/usr/local/nginx/conf/nginx.conf;有三大块内容:全局配置、I/O事件配置、HIIP配置;配置语句的格式为“关键字 值;”(末尾以分号表示结束),“#”开始为注释

 2.1全局配置   解释:

[root@C7--01 ~]# vim /usr/local/nginx/conf/nginx.conf#user  nobody;                           #运行用户
worker_processes  1;                     #工作进程数量;可参考CPU核心总数指定工作进程数,网站访问量越大,进程数设置越多#error_log  logs/error.log;              #错误日志文件的位置
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;              #PID文件位置
......
..

 2.2  I/O事件配置   解释:

events {                       #使用events界定标记指定nginx进程的I/O响应模型,每个进程连接数等use epoll;                 #使用epoll模型,提高性能worker_connections  4096;  #每个进程处理4096个连接(默认为1024:每个进程的连接数量一般在50000以下根据实际情况设置)
}

 注意:如工作进程数是 8;每个进程处理4096 个连接,则Nginx 提供服务的连接数是(4096X8);具体看服务器硬件和网络带宽等物理条件性能等

 2.3 HTTP配置    解释:

[root@C7--01 ~]# vim /usr/local/nginx/conf/nginx.conf
http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;            #访问日志位置sendfile        on;                            #开启高效传输文件模式#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;                         #连接保持超时#gzip  on;server {                                       #web服务的监听配置listen       80;                           #监听地址及端口server_name  localhost;                    #网站名称#charset koi8-r;                           #网页的默认字符集#access_log  logs/host.access.log  main;location / {                               #根目录配置root   html;                           #网站根目录的位置,相对于安装目录index  index.html index.htm;           #默认首页(搜引页)}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;   #内部错误的反馈页面location = /50x.html {                     #错误页面配置root   html;}
.........
....}
nginx中的location语法:location [  = / ~ / ~* / ^~]   /uri/  { … }
=开头表示精确匹配
~开头表示区分大小写的正则匹配
~*开头表示不区分大小写的正则匹配
!~和!~*分别为区分大小写不匹配及不区分大小写不匹配 的正则
/通用匹配,任何请求都会匹配到
^~开头表示uri以某个常规字符串开头,理解为匹配 url路径即可。nginx不对url做编码,因此请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到(注意是空格)
匹配顺序仅供参考:首先匹配 =,其次匹配^~, 其次是按文件中顺序的正则匹配,最后是交给 /通用         匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求

 3、访问状态统计及虚拟主机应用

 编辑配置文件:把原配置文件修改名字为nginx.conf.bak

[root@C7--01 ~]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak                        

新建nginx.conf配置文件进行编辑

[root@C7--01 ~]# vim /usr/local/nginx/conf/nginx.confworker_processes  1;
events {use epoll;worker_connections  4096;
}
http {include       mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  logs/access.log  main;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  www.aaa.com;charset utf-8;location / {root   html;index  index.html index.php;}location /status {                        #访问位置:/statusstub_status on;                   #打开状态统计功能access_log off;                   #关闭此位置的日志记录}                error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}
}[root@C7--01 ~]# nginx -t    # 检查配置文件
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@C7--01 ~]# systemctl start nginx           #启动nginx
[root@C7--01 ~]# systemctl status nginx          #查看状态
● nginx.service - SYSV: Nginx Server Control ScriptLoaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)Active: active (exited) since 六 2021-08-28 00:36:18 CST; 19h agoDocs: man:systemd-sysv-generator(8)Process: 46093 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)

 访问测试:IE浏览器  http://192.168.1.1/status

当前的状态统计信息
Active conmections表示当前的活动连接数     1
server accepts handled requests

表示已经处理的连接信息

三个数依次是:已处理的连接数(1)、成功的TCP握手次数(1)、已处理的请求数(1)

 Reading: 0 Writing: 1 Waiting: 0读取状态  写入状态   等待状态
[root@C7--01 ~]# elinks --dump http://192.168.1.1/statusActive connections: 1 server accepts handled requests 1 1 1 Reading: 0Writing: 1 Waiting: 0

 图形化测试

3.1部署NGINX虚拟主机

方法一:配置DNS服务

[root@C7--01 ~]# yum -y install bind    #安装dns服务
.......
...
[root@C7--01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33   #进入网卡
......
..
DNS1=192.168.1.1       #添加dns地址保存退出[root@C7--01 ~]# systemctl restart network        #重启网卡
[root@C7--01 ~]# cat /etc/resolv.conf             #查看dns
# Generated by NetworkManager
search 1
nameserver 192.168.1.1

修改主配置文件

[root@C7--01 ~]# vim /etc/named.conf
options {listen-on port 53 { 192.168.1.1; };                   #修改成地址为192.168.1.1listen-on-v6 port 53 { ::1; };directory       "/var/named";dump-file       "/var/named/data/cache_dump.db";statistics-file "/var/named/data/named_stats.txt";memstatistics-file "/var/named/data/named_mem_stats.txt";allow-query     { any; };                            #允许全部网段访问
.......
....
zone "." IN {type hint;file "named.ca";
};zone "mac.com" IN {          #添加mac.comtype master;file "mac";          #文件 mac
};zone "aaa.com" IN {          #添加aaa.comtype master;file "aaa";            #文件aaa
};保存退出

编辑区域配置文件

[root@C7--01 ~]# cd /var/named
[root@C7--01 named]# cp named.localhost aaa    #复制named.localhost,名称修改为aaa
[root@C7--01 named]# cp named.localhost mac    #复制named.localhost,名称修改为mac
[root@C7--01 named]# vim mac              #修改mac区域配置文件$TTL 1D
@       IN SOA  mac.com. admin.mac.com. (2021082101      ; serial1D      ; refresh1H      ; retry1W      ; expire3H )    ; minimumNS      www.mac.com.MX  10  mail.mac.com.
www     IN   A  192.168.1.1保存退出[root@C7--01 named]# vim aaa             #修改aaa区域文件$TTL 1D
@       IN SOA  aaa.com. admin.aaa.com. (2021080902      ; serial1D      ; refresh1H      ; retry1W      ; expire3H )    ; minimumNS      www.aaa.com.MX  10  mail.aaa.com.
www     IN   A  192.168.1.1

 更改区域文件和主配置文件的权限

[root@C7--01 named]# chown named:named aaa     #修改属主:属组
[root@C7--01 named]# chown named:named mac     #修改属主:属组
[root@C7--01 named]# chown named:named /etc/named.conf  #修改属主:属组
[root@C7--02 ~]# systemctl start named           #启动dns服务

测试:解析dns两个域名成功都是一个ip地址

C:\Users\wrzs0> nslookup  
默认服务器:  UnKnown
Address:  192.168.1.1>
> www.aaa.com
服务器:  UnKnown
Address:  192.168.1.1名称:    www.aaa.com
Address:  192.168.1.1> www.mac.com
服务器:  UnKnown
Address:  192.168.1.1名称:    www.mac.com
Address:  192.168.1.1

 方法二:进入hosts文件添加(hosts文件是负责ip地址与域名快速解析的文件

[root@C7--01 ~]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.1 www.aaa.com
192.168.1.1 www.mac.com

准备网站目录和测试文件

[root@C7--01 ~]# cd /usr/local/nginx/html      #进入目录
[root@C7--01 html]# ls
50x.html  index.html
[root@C7--01 html]# mkdir aaa                  #新建html根目录aaa
[root@C7--01 html]# mkdir mac                  #新建html根目录mac
[root@C7--01 html]# ls
50x.html  aaa  index.html  mac

编辑html首页

[root@C7--01 html]# vim aaa/index.htmlaaa <h1>今天天气真好<h1/>[root@C7--01 html]# vim mac/index.htmlmac <h3>欢迎来到王者峡谷<h3/>

 调整nginx.conf配置文件(建议删除访问状态统计配置

[root@C7--01 ~]# vim /usr/local/nginx/conf/nginx.confworker_processes  1;
events {use epoll;worker_connections  4096;
}
http {include       mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  logs/access.log  main;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  www.aaa.com;                   #修改网站名称charset utf-8;location / {root   /usr/local/nginx/html/aaa;       #修改网站根目录index  index.html index.php;}}server {listen       80;server_name  www.mac.com;                   #修改网站名称charset utf-8;location / {root   /usr/local/nginx/html/mac;       #修改网站根目录index  index.html index.php;}}
}[root@C7--01 ~]# nginx -t                         #检查配置文件
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@C7--01 ~]# elinks --dump http://www.aaa.com   #字符界面访问aaa今天天气真好
[root@C7--01 ~]# elinks --dump http://www.mac.commac欢迎来到王者峡谷

 图形化访问

 

二、LNMP架构及应用部署

LNMP平台的构成:Linux服务器、MySQL数据库、PHP解析环境、Nginx (和LAMP一样需要Linux服务器、MySQL数据库、PHP解析环境)

LNMP和LAMP的区别:在Nginx与PHP的协作配置上

 1、搭建LNMP网站平台

1.1、安装MYSQL数据库(三章———Mysql数据库系统3.1)

安装步骤按照:三章———Mysql数据库系统3.1 安装

1.2、安装PHP解析环境

编译安装PHP

[root@C7--02 ~]# yum -y install libxml2-devel gd zlib-devel libjpeg-devel libpng-devel
已加载插件:fastestmirror
aaa                                                                                                 | 3.6 kB  00:00:00  
......
...[root@C7--02 ~]# tar xf php-5.5.38.tar.gz -C /usr/src
[root@C7--02 ~]# cd /usr/src/php-5.5.38/[root@C7--02 php-5.5.38]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib           
......
...[root@C7--02 php-5.5.38]# make && make install
.........
.....[root@C7--02 php-5.5.38]# ls /usr/local/php5/
bin  etc  include  lib  php  sbin  var

安装后调整

[root@C7--02 php-5.5.38]# cp php.ini-development /usr/local/php5/php.ini               
[root@C7--02 ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@C7--02 ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/

安装ZendGuardLoader

[root@C7--02 ~]# tar xf zend-loader-php5.5-linux-x86_64_update1.tar.gz   #解压
[root@C7--02 ~]# cd zend-loader-php5.5-linux-x86_64[root@C7--02 zend-loader-php5.5-linux-x86_64]# ls                        #查看
opcache.so  README.txt  ZendGuardLoader.so[root@C7--02 zend-loader-php5.5-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php/                    [root@C7--02 zend-loader-php5.5-linux-x86_64]# cd
[root@C7--02 ~]# vim /usr/local/php5/php.ini                            #进入php.ini文件
.........
.....
;curl.cainfo =; Local Variables:
; tab-width: 4
; End:
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so      #在最下面添加
zend_loader.enable=1                                            #在最下面添加

1.3配置nginx支持PHP环境

 启用php-fpm进程(默认端口号为9000)

[root@C7--02 ~]# cd /usr/local/php5/etc/
[root@C7--02 etc]# useradd -M -s /sbin/nologin php     #创建用户php[root@C7--02 etc]# vim php-fpm.conf                    #创建新配置文件[global]
pid = run/php-fpm.pid        #确认pid文件位置
[www]
listen = 127.0.0.1:9000
user = php                   #运行用户
group = php                  #运行组
pm = dynamic
pm.max_children = 50         #最多空闲进程数
pm.start_servers = 20        #启动时开启的进程数
pm.min_spare_servers = 5     #最少空闲进程数
pm.max_spare_servers = 35 保存退出[root@C7--02 etc]# /usr/local/php5/sbin/php-fpm      #启动进程
[root@C7--02 etc]# netstat -utpln | grep php         #查看
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      104914/php-fpm: mas [root@C7--02 ~]# killall -9 php-fpm         #关闭进程
[root@C7--02 ~]# netstat -utpln | grep php  #查看

新建LNMP启动脚本:可以在启动或停止 nginx 服务器时php-fpm进程也可以启动或停止

[root@C7--02 ~]# vim /etc/init.d/lnmp
#!/bin/bash
# chkconfig: 35 95 30
# description: This script is for LNMP Management!
NGF=/usr/local/nginx/sbin/nginx
NGP=/usr/local/nginx/logs/nginx.pid
FPMF=/usr/local/php5/sbin/php-fpm
FPMP=/usr/local/php5/var/run/php-fpm.pid
case $1 in start)$NGF &&echo "nginx is starting! "$FPMF && echo "php-fpm is starting! ";;stop)kill -QUIT $(cat $NGP) &&echo "nginx is stoped! "kill -QUIT $(cat $FPMP) &&echo "php-fpm is stoped! ";;restart)$0 stop$0 start;;reload)kill -HUP $(cat $NGP) kill -HUP $(cat $FPMP);;status)netstat -utpln |grep nginx &>/dev/null if [  $? -eq 0 ]thenecho "nginx is running! "elseecho "nginx is not running! "finetstat -upltn |grep php-fpm &>/dev/null if [ $? -eq 0 ]thenecho "php-fpm is runing! "elseecho "php-fpm is not running! "fi;;*)echo "Usage $0 {start|stop|status|restart}"exit 1;;
esac
exit 0保存退出[root@C7--02 ~]# chmod +x /etc/init.d/lnmp     #赋予执行权限
[root@C7--02 ~]# chkconfig --add lnmp          #加入到系统服务

确认php-fpm、nginx服务已停止

[root@C7--02 ~]# netstat -anput | grep php-fpm  #查看
[root@C7--02 ~]# nginx -s stop                  #停止nginx服务
[root@C7--02 ~]# netstat -naput | grep nginx    #查看

 同时启动php-fpm、nginx服务

[root@C7--02 ~]# systemctl start lnmp     #同时启动[root@C7--02 ~]# systemctl status lnmp    #查看状态
● lnmp.service - SYSV: This script is for LNMP Management!Loaded: loaded (/etc/rc.d/init.d/lnmp; bad; vendor preset: disabled)Active: active (running) since 日 2021-08-29 22:50:39 CST; 21s agoDocs: man:systemd-sysv-generator(8)Process: 122085 ExecStart=/etc/rc.d/init.d/lnmp start (code=exited, status=0/SUCCESS)CGroup: /system.slice/lnmp.service├─122087 nginx: master process /usr/local/nginx/sbin/nginx├─122089 nginx: worker process├─122090 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf)├─122091 php-fpm: pool www├─122092 php-fpm: pool www├─122093 php-fpm: pool www├─122094 php-fpm: pool www├─122095 php-fpm: pool www├─122096 php-fpm: pool www├─122097 php-fpm: pool www├─122098 php-fpm: pool www├─122099 php-fpm: pool www├─122100 php-fpm: pool www├─122101 php-fpm: pool www├─122102 php-fpm: pool www├─122103 php-fpm: pool www├─122104 php-fpm: pool www├─122105 php-fpm: pool www├─122106 php-fpm: pool www├─122107 php-fpm: pool www├─122108 php-fpm: pool www├─122109 php-fpm: pool www└─122110 php-fpm: pool www8月 29 22:50:39 C7--02 systemd[1]: Starting SYSV: This script is for LNMP Management!...
8月 29 22:50:39 C7--02 lnmp[122085]: nginx is starting!
8月 29 22:50:39 C7--02 lnmp[122085]: php-fpm is starting!
8月 29 22:50:39 C7--02 systemd[1]: Started SYSV: This script is for LNMP Management!.
[root@C7--02 ~]# 

 如果服务启动错误就杀死进程:[root@C7--02 ~]# killall -9 nginx   在重启LNMP


 配置nginx支持PHP解析

   让Nginx能够解析PHP网页有两种方法:一,访问PHP页面的Web请求转交给其他服务器(LAMP)去处理;二,使用PHP的FPM模块来调用本机的PHP环境                        无论将PHP页面交给LAMP服务器去解析,还是调用本机的php-fpm进程进行解析,都需要在“server { } ”配置段中添加location设置,以便指定访问php网页时采取何种操作

 方法一转交给LAMP服务器:   (注意:\.php 输入错误会导致访问失败)

[root@C7--02 ~]# vim /usr/local/nginx/conf/nginx.conf......
...server {listen       80;server_name  www.benet.com;charset utf-8;location ~ \.php$ {                          #访问.php页面的配置段proxy_pass http://目标主机ip地址:80;      #apache服务器的监听地址}

 方法二调用本机的php-fpm进程解析:(本次实验使用方法二) (注意:\.php 输入错误会导致访问失败)

[root@C7--02 ~]# vim  /usr/local/nginx/conf/nginx.confworker_processes  1;
events {use epoll;worker_connections  4096;
}
http {include       mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  logs/access.log  main;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  www.mac.com;charset utf-8;access_log logs/mac.access.log;location / {root   /usr/local/nginx/html/mac;index  index.html index.php;}location ~ \.php$ {root /usr/local/nginx/html/mac;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}}
}

 创建测试php网页

[root@C7--02 ~]# mkdir /usr/local/nginx/html/mac   #创建目录
[root@C7--02 ~]# vim /usr/local/nginx/html/mac/test.php   #创建访问首页mysql数据库用户名root密码123.com
<?php
$link=mysqli_connect('localhost','root','123.com');
if($link) echo "<h1>访问数据库成功 !!</h1>";
mysqli_close($link);
?>

2、在LNMP平台中部署web应用

  LNMP平台与LAMP平台是非常相似的,区别在于所用Web服务软件的不同,而这与使用PHP开发的Web应用程序并无太大关系,因此PHP应用的部署方法也是类似的

2.1部署程序代码

[root@C7--02 ~]# yum -y install unzip
[root@C7--02 ~]# unzip Discuz_X3.3_SC_UTF8.zip   #解压discuz!社区论坛
[root@C7--02 ~]# mv upload/ /usr/local/nginx/html/mac/sqlt   #把upload剪切到LNMP服务器的网站根目录下
[root@C7--02 ~]# chown -R php:php /usr/local/nginx/html/mac/sqlt  #设置属主:属组,让nginx、php-fpm程序写入权限[root@C7--02 ~]# mysql -uroot -p123.com         #进入mysql数据库
.......
...
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database sqlt;             #创建库sqlt
Query OK, 1 row affected (0.00 sec)mysql> grant all on sqlt.* to aaa@localhost identified by '123.com';    #创建用户aaa密码为123.com 可以对sqlt库拥有所有权限
Query OK, 0 rows affected (0.01 sec)mysql> quit          #退出
Bye

输入: http://www.mac.com/sqlt/install/index.php

 

 

 稍等片刻就可以访问  www.mac.com/sqlt/forum.php 

管理后台:http://www.mac.com/sqlt/admin.php

 输入之前给的管理员账号和密码就可以管理社区论坛了

复习题

1、简述LNMP平台的构成组件,以及与LAMP平台的区别 

LNMP平台的构成:Linux服务器、MySQL数据库、PHP解析环境、Nginx

区别:在于所用Web服务软件的不同

2、在编译安装Nginx时通过指定什么选项添加提供访问统计的stub_status模块?

指定:http_stub_status_module提供访问统计的stub_status模块

3、在Linux系统中执行killall -s HUP nginx与killall -s QUIT nginx命令的作用分别是什么?

-s HUP 相当于 -1:重新加载配置

-s QUIT 相当于 -3:停止服务​​​​

4、在Nginx的配置文件中,哪几个配置参数决定了正常服务的连接数?

events {
use   epoll; 
worker_connections  1024;
}

5、在Nginx配置文件的server { }配置段中,root语句的作用是什么?

作用:网站根目录的位置,相对于安装目录

6、使用Nginx的状态统计功能除了启用内建模块外,还需要在配置文件中添加哪些内容?

需要添加:
location /status   {             #访问位置为/statusstub status on;             #打开状态统计功能access log off;              #关闭此位置的日志记录
}

7、简述Nginx配置虚拟主机的方法与流程

(1)准备网站目录及测试文件  (2)调整nginx.conf配置文件  (3)测试虚拟Web主机

8、mysqladmin -u root password 'pwd123'命令的作用什么?

给mysqi数据库的root用户设置密码

9、Nginx对PHP的支持可以通过哪两种方式实现?

1)把访问 PHP 页面的 Web 请求转交给其他服务器(LAMP)处理

2)使用PHP的FPM模块来调用本机的 PHP 环境

10、写出php-fpm程序的启动方法与默认监听端口

启动方法:/usr/local/sbin/php-fpm

默认监听端口:9000

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_769443.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

rust全息要啥才能做_网站优化要怎么做才能排名靠前-乐云SEO

对于一个网站来说&#xff0c;网站优化是重要的&#xff0c;只有在搜索引擎中的关键词排名靠前才能获得更多的点击量。一个没有用户点击量的网站&#xff0c;即使它是完美的&#xff0c;是徒劳的。那么&#xff0c;我们如何在百度或其他搜索引擎的主页上获得网站的关键词排名呢…

实验楼网站mysql_进阶篇 - MySQL 常用查询

实验9 进阶篇-MySQL常用查询一、简介1. 内容&#xff1a;通过一个经销商数据库实例学习并实践多种在数据库中查找记录的方法。2. 知识点&#xff1a;表查询操作。二、步骤1. 启动并连接MySQL。创建切换数据库。创建表并插入数据。mysql> CREATE TABLE shop (-> article I…

java 爬虫 登陆_Java 爬虫遇到需要登录的网站,该怎么办?

这是 Java 网络爬虫系列博文的第二篇&#xff0c;在上一篇 Java 网络爬虫&#xff0c;就是这么的简单 中&#xff0c;我们简单的学习了一下如何利用 Java 进行网络爬虫。在这一篇中我们将简单的聊一聊在网络爬虫时&#xff0c;遇到需要登录的网站&#xff0c;我们该怎么办&…

php行业八卦,Phpwind肖睿哲:与网站主合作信任最重要

(图为&#xff1a;Phpwind副总裁肖睿哲)【TechWeb消息】12月4日下午消息&#xff0c;Phpwind副总裁肖睿哲在“2010年中国地方与行业网站高峰论坛”上接受TechWeb专访时表示&#xff0c;与新浪微博合作产生利益之后&#xff0c;网站主将会与新浪微博七三分成&#xff0c;“Phpwi…

java请求爬取https网站报错javax.net.ssl.SSLHandshakeException的解决办法

前言 在爬取https网站的时候&#xff0c;今天遇到了一个之前没有见过的异常javax.net.ssl.SSLHandshakeException&#xff0c;具体细节请看如图 2020-06-01 23:18:17.032 DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request javax.ne…

不同网站不同网卡_不同时代网站设计制作的技巧

对于大多数网页设计师来说&#xff0c;基于特定的目标受众来计划一个网站设计项目是显而易见的。它可能是为那些喜欢苏打水或购买电子游戏或对运动鞋有亲和力的人。但是另一个需要考虑的问题经常被忽略——为不同的时代的用户设计。年龄会影响用户如何使用网站、应用程序和移动…

win7网站服务器错误怎么解决方法,win7系统网页提示network error怎么办|win7 network error的解决方法...

‍‍有很多win7旗舰版用户在访问网页的时候出现无法访问的情况&#xff0c;并提示network error&#xff0c;我们遇到在win7系统网页提示network error怎么办呢&#xff1f;会出现network error很有可能是网络参数发现错误或接触DNS服务器发生错误导致二级网页打不开&#xff0…

做网站用UTF-8编码还是GB2312编码?

经常我们打开外国网站的时候出现乱码&#xff0c;又或者打开很多非英语的外国网站的时候&#xff0c;显示的都是口口口口口的字符&#xff0c; WordPress程序是用的UTF-8&#xff0c;很多cms用的是GB2312。 ● 为什么有这么多编码&#xff1f; ● UTF-8和GB2312有什么区别&…

MOSS 2007应用日记(3)——如何创建/删除部门网站(子网站)

在顶级网站中&#xff0c;我们可以为各个部门创建自己的网站1创建部门网站&#xff08;子网站&#xff09;登录顶级网站&#xff0c;点击页面右上角的“网站操作”&#xff0c;选择“创建网站”输入网站的标题和说明&#xff0c;这里创建一个“行政部”网站在“网站网址”中输入…

用linux部署一个网站,Linux网站部署——从零到一部署一个本身的电商网站

上一篇关于部署论坛的网站已经发出&#xff0c;此次咱们来部署一下电商网站&#xff0c;前期的准备工做请参考上篇文章&#xff1a;https://editor.csdn.net/md/?articleId114901490php我在这里直接借用了一个云服务器。若是仍是本身服务器的同窗能够直接使用咱们的第一条命令…

服务器安装网站流程图,服务器操作系统的安装流程图

服务器操作系统的安装流程图 内容精选换一换外部镜像文件在从原平台导出前&#xff0c;没有按照“Windows操作系统的镜像文件限制”的要求完成初始化操作&#xff0c;推荐您使用弹性云服务器完成相关配置。流程如图1所示。云服务器的正常运行依赖于XEN Guest OS driver(PV driv…

证书 手机打不开页面_教师资格证报名入口网站打不开怎么办|教师资格证报名浏览器是哪个...

为了帮助考生解决“教师资格证报名入口网站打不开怎么办|教师资格证报名浏览器是哪个”相关的问题&#xff0c;中公教师网通过相关资料这些问题进行了整理&#xff0c;具体解决办法如下&#xff1a;相关推荐>>>2021上半年教师资格证报名入口|报名时间-中小学教师资格考…

Flash与组件:国外收费组件网站

http://www.flashcomponents.net/index.html 今天无意中光顾了这个国外flash组件网站&#xff0c;虽然基本上上都是收费但是可给我们提供一些灵感&#xff0c;同时也让我们扩展视野是个不错的平台。国内也是非常少见&#xff0c;有这样的情况。

域名怎么进行html校验,百度站长平台如何进行网站验证及常见问题

原标题&#xff1a;百度站长平台如何进行网站验证及常见问题为什么我们把网站验证到百度搜索资源平台百度搜索资源平台推荐站长添加主站(您网站的链接也许会使用www 和非 www 两种网址&#xff0c;建议添加用户能够真实访问到的网址)&#xff0c;添加并验证后&#xff0c;可证明…

网页中直接调用计算机程序,深入探讨 网站想要使用你计算机上的程序打开Web内容...

深入探讨 网站想要使用你计算机上的程序打开Web内容gOxiA 因为工作需要最近在做与桌面虚拟化相关的技术内容&#xff0c;期间就遇到了“网站想要使用你计算机上的程序打开 Web 内容”的问题。具体是在用户安装 VDA 客户端后&#xff0c;通过 IE 访问 VDI 门户时会弹出这个提示&…

怎样查看网站服务器时间,如何查看docker容器的时间_网站服务器运行维护

如何把宿主机的文件拷贝到docker中_网站服务器运行维护把宿主机的文件拷贝到docker中的方法&#xff1a;在宿主机里执行“docker cp要拷贝的文件路径容器名&#xff1a;要拷贝到容器里面对应的路径”命令即可。查看docker容器时间的方法&#xff1a;进入到容器里执行date命令即…

python之scrapy实战篇(爬取电影网站的相关信息)

缘由&#xff1a; 由于我是一个比较喜欢看电影的人&#xff0c;但是又是个孩子&#xff0c;所以技术改变生活&#xff0c;虽然说直接打开浏览器下载就好了&#xff0c;但是我懒&#xff0c;所以借此机会用Scrapy框架来简单爬取一个电影网站 需要获取的信息&#xff1a; --电…

40个漂亮的HTML5供电的网站,为你的灵感

HTML4&#xff0c;执政超过10年后&#xff0c;现在正在取代HTML5&#xff0c;它具有更先进的多媒体融合和动画功能。由于向后兼容的&#xff0c;它可以运行在几乎所有的浏览器包括移动平台&#xff0c;提供更快的加载速度&#xff0c;更流畅的第三方应用程序的连接。许多开发人…

MEC Magento系列采用Magento建站技术——全新的电子商务建站革命技术

2019独角兽企业重金招聘Python工程师标准>>> MEC Magento系列采用全球最先进的Magento建站技术&#xff0c;构建超低价格却极高优越性能的外贸网店系统&#xff0c;具有几近无限的二次开发和系统扩展可能性。 Magento建站技术框架受到全球众多500强企业和顶级知名品…

帮你早点下班~基于飞书API实现next.js网站内容自动生成实践

前言 最近在公司里得到了一项任务&#xff0c;人事给了一个 飞书的职位表格 &#xff0c;要求将里面的信息更新到官网上面去。其中涉及了已有岗位的信息更新&#xff0c;删除部分岗位和添加部分岗位。这种工作虽然简单&#xff0c;但是很琐碎&#xff0c;很麻烦。 三十个岗位…