Nginx 服务器建立与php语言的解析_nginx php

服务器 0

安装Nginx的开发环境

yum install pcre-devel zlib-devel -y
在这里插入图片描述
出现complete就安装好了
在这里插入图片描述

第二步

创建一个系统程序用户赋予nginx这个用户只能执行某个程序的权限而不能登录

useradd -u 251 -M -s /sbin/nologin nginx
-s  指定用户登入后所使用的shell -u 用户uid -M 不要自动建立用户的登入目录家目录 要拒绝系统用户登录,可以将其 shell 设置为 /usr/sbin/nologin 或者 /bin/false。
在这里插入图片描述

第三步

对下载好的Nginx压缩包放进服务器里进行解压缩编译

进行解压tar xf nginx-1.6.0.tar.gz
在这里插入图片描述
nginx-1.6.0就是文件所在的目录了

进入目录就进行预编译./configure --prefix=/usr/local/nginx_1.6.0 --user=nginx --group=nginx
/usr/local是安装路径一般用户自己安装的程序都在该目录下
在这里插入图片描述
一定要在该目录下

用make进行编译
在这里插入图片描述

编译完成之后使用make install进行安装
在这里插入图片描述

安装完成

安装php环境

要实现动态脚本需要安装php

yum install php php-mysql php-mbstring -y
在这里插入图片描述
安装完成
在这里插入图片描述

启动Nginx

nginx命令因为未设置环境变量所以要用绝对路径启动/usr/local/nginx-1.6.0/sbin/nginx
在这里插入图片描述
以下的所有参数

 -?,-h        		 this help  -v            	 show version and exit  -V             	 show version and configure options then exit  -t            	 test configuration 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_1.6.0/)  -c filename  		 set configuration file (default: conf/nginx.conf)  -g directives 	 set global directives out of configuration file

nginx安装成功
在这里插入图片描述

停止服务

/usr/local/nginx_1.6.0/sbin/nginx -s stop

Nginx和php

Nginx默认是不支持php的要想使用是需要进行配置的

Nginx和php是两个程序

两个应用程序想要交互需要通信

CGI是一种标准的协议

通过CGI这种协议进行通信

Nginx 本身并不会对PHP 文件进行解析,不具备将PHP 作为自身模块的功能。Nginx 负责找到文件,PHP 负责处理文件,所以需要开启Nginx 与PHP 进程间通信。如何实现呢?要求PHP 开启一个进程,来监听请求,处理PHP 脚本。Nginx 把对PHP 页面的请求交给PHP 监听的进程来处理,这个进程就是FastCGI,FastCGI 是一种技术,会监听一个IP 地址及端口,如,127.0.0.1:9000。

PHP 使用php-fpm 对FastCGI 技术进行实现与管理,php-fpm 作为动态解析PHP 的服务器。php-fpm 将处理后的结果交给Nginx。

Nginx 通过反向代理功能将动态请求转向后端php-fpm,从而实现对PHP 的解析支持。

php-fpm

要想让nginx可以使用php需要安装fpm模块

安装php-fpm

yum install php-fpm -y
在这里插入图片描述
安装成功
在这里插入图片描述

启动服务

systemctl start php-fpm
在这里插入图片描述

该服务监听的是9000端口
在这里插入图片描述

Nginx解析php

Nginx的配置文件在/usr/local/nginx-1.6.0/conf下的nginx.conf
在这里插入图片描述

先将配置文件进行备份以免配置错误后可恢复
先cd到/usr/local/nginx-1.6.0/conf下
进行备份cp nginx.conf nginx.conf.bak

在这里插入图片描述

配置文件解析
# 全局配置#user nobody; # Nginx 进程所使用的用户worker_processes  1;                # Nginx 运行的work 进程数量(建议与CPU 数量一致或auto)#error/_log logs/error.log; # Nginx 错误日志存放路径#error/_log logs/error.log notice;#error/_log logs/error.log info;#pid logs/nginx.pid; # Nginx 服务运行后产生的pid 进程号# I/O 事件配置events {    use epoll;                  # 事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport                                # linux - epoll,FreeBSD - kqueue,window下不指定。    worker_connections  1024;   # 每个进程最大连接数。}# HTTP 配置模块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;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #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;        # fastcgi/_param SCRIPT/_FILENAME /scripts$fastcgi/_script/_name;        # include fastcgi/_params;        #}        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ //.ht {        # deny all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    # listen 8000;    # listen somename:8080;    # server/_name somename alias another.alias;    # location / {    # root html;    # index index.html index.htm;    # }    #}    # HTTPS server    #    #server {    # listen 443 ssl;    # server/_name localhost;    # ssl/_certificate cert.pem;    # ssl/_certificate/_key cert.key;    # ssl/_session/_cache shared:SSL:1m;    # ssl/_session/_timeout 5m;    # ssl/_ciphers HIGH:!aNULL:!MD5;    # ssl/_prefer/_server/_ciphers on;    # location / {    # root html;    # index index.html index.htm;    # }    #}}

在配置文件的server里的配置 可以配置监听端口,首页网站等信息

php的配置在64行中

在这里插入图片描述

对文件进行编辑vim nginx.conf
在这里插入图片描述

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注网络安全获取)
img

还有兄弟不知道网络安全面试可以提前刷题吗?费时一周整理的160+网络安全面试题,金九银十,做网络安全面试里的显眼包!

王岚嵚工程师面试题(附答案),只能帮兄弟们到这儿了!如果你能答对70%,找一个安全工作,问题不大。

对于有1-3年工作经验,想要跳槽的朋友来说,也是很好的温习资料!

【完整版领取方式在文末!!】

93道网络安全面试题

内容实在太多,不一一截图了

黑客学习资源推荐

最后给大家分享一份全套的网络安全学习资料,给那些想学习 网络安全的小伙伴们一点帮助!

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

1️⃣零基础入门
① 学习路线

对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。

image

② 路线对应学习视频

同时每个成长路线对应的板块都有配套的视频提供:

image-20231025112050764

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
img

/img-blog.csdnimg.cn/img_convert/acb3c4714e29498573a58a3c79c775da.gif#pic_center)

② 路线对应学习视频

同时每个成长路线对应的板块都有配套的视频提供:

image-20231025112050764

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-LPEvJ5Ix-1712852590616)]

也许您对下面的内容还感兴趣: