nginx----web服务器
一、nginx
http就是apache,在国内很少。
nginx是开源的,是一款高性能,轻量级的web服务软件。
稳定性高,而且版本迭代比较快(修复bug速度比较快,安全性快)
消耗系统资源很低,http的请求并发连接,单台服务器开源支持30000-50000个并发请求。(系统资源全部分配给nginx)
单个节点的nginx一般支持20000个并发。
1.1、nginx的功能:
1、静态文件服务:静态页面,可以直接提高静态文件服务,html css jsp。处理静态页面的响应速度很快,效率很好。
2、代理:正向代理,反向代理。可以实现负载均衡,高可用和故障转移。
3、动态内容处理,nginx并不能直接处理动态请求,可以通过中间件nginx 中间件(php,tomat) mysql把动态请求转发给后端服务器。
4、支持加密的http,https
5、可以实现重定向。
6、虚拟主机,一个nginx可以配置多个域名和站点。
7、nginx自带缓存。
8、性能可以扩展。处理能力可以随时调整。
1.2、nginx的应用场景:
-
静态页面
-
转发动态请求
-
反向代理,负载均衡
-
缓存服务
1.3、编译过程中代码解释
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \ ##支持https的加密功能ss/tls
--with-http_v2_module \ ##支持http2.0协议
--with-http_realip_module \ ##支持nginx获取客户端的真实ip地址
--with-http_stub_status_module \ ##支持nginx获取访问状态信息的功能
--with-http_gzip_static_module \ ##支持页面压缩功能
--with-pcre \ ##支持prce库
--with-stream \ ##支持4层代理的模块
--with-stream_ssl_module \ ##支持对tcp连接的加密
--with-stream_realip_module ##支持从代理协议中获取客户端的真实ip地址
make -j4 && make install
#启动四个cpu进行
conf
配置文件目录
html
工作目录 50x.html
默认的访问操作打开的页面
index.html
默认的访问主页
logs
日志目录 访问和报错日志
sbin
nginx的二进制启动脚本
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
#让系统识别nginx的二进制脚本
1.3.1、nginx的常用命令
nginx -t
检测nginx.conf配置文件的语法是否正确
nginx -v
显示nginx的版本
nginx -V
显示版本和配置项
nignx -s
信号 stop 关闭nginx
reload
重新加载nginx,如果更改了配置文件,nginx -s reload 无需重新启动服务。
systemctl daemon-reload
二、课后重新编译安装nginx
rpm -q nginx ##检查yum是否安装
yum -y remove nginx ##有则卸载
cd /opt
rz -E
rz waiting to receive.
systemctl stop firewalld ##关闭安全机制
setenforce 0
yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel ##配置编译环境
useradd -M -s /sbin/nologin nginx ##添加程序用户
tar -xf nginx-1.22.0.tar.gz ##源码解压
cd /nginx-1.22.0/ ## 进入nginx的文件夹,配置暗转路径,以及相关组件
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
make -j 4 && make install ##编译和安装
[root@test1 nginx-1.22.0]# cd /usr/local/
[root@test1 local]# ls
bin etc games include lib lib64 libexec nginx sbin share src
chown -R nginx.nginx nginx/ ##更改权限
[root@test1 local]# cd nginx
[root@test1 nginx]# ll
总用量 4
drwxr-xr-x. 2 nginx nginx 4096 7月 1 16:04 conf
drwxr-xr-x. 2 nginx nginx 40 7月 1 16:04 html
drwxr-xr-x. 2 nginx nginx 6 7月 1 16:04 logs
drwxr-xr-x. 2 nginx nginx 19 7月 1 16:04 sbin
[root@test1 nginx]# cd conf/
[root@test1 conf]# ls
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[root@test1 conf]# cd ..
[root@test1 nginx]# ls
conf html logs sbin
[root@test1 nginx]# cd html/
[root@test1 html]# ls
50x.html index.html
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ ##做一个软连接,让系统能够识别nginx的指令
[root@test1 opt]# nginx -t
nginx: the configurati