#nginx官网

http://nginx.org/

#nginx主要代理七层协议,也就是应用层;nginx是一个高性能HTTP和反向代理,负载均衡服务器.............


#nginx默认端口是80

#https默认端口是443


#官网查看安装步骤

http://nginx.org/——>documentation——>Installing nginx——>Installation on Linux, packages——>RHEL and derivatives——>

#使用yum安装nginx

#配置yum源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true


#开始安装

[root@yang-1 ~]# yum install -y nginx


#查看版本

[root@yang-1 ~]# nginx -v
nginx version: nginx/1.24.0


#使用nginx -t检测配置文件时显示默认生成的nginx配置文件

[root@yang-1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


#启动服务,查看状态

[root@yang-1 ~]# nginx
[root@yang-1 ~]# ps aux |grep nginx
root      33379  0.0  0.0  48956  1172 ?        Ss   22:06   0:00 nginx: master process nginx
nginx     33380  0.0  0.0  51428  2040 ?        S    22:06   0:00 nginx: worker process
nginx     33381  0.0  0.0  51428  2040 ?        S    22:06   0:00 nginx: worker process
root      33384  0.0  0.0 112724   988 pts/0    R+   22:06   0:00 grep --color=auto nginx
[root@yang-1 ~]#

###

#源码编译部署nginx

#官网下载源码

http://nginx.org/——>documentation——>nginx-1.24.0  pgp


#上传源码文件到linux机器上,到指定目录,或者使用wget下载

[root@yang-1 ~]# cd /usr/local/src/
[root@yang-1 src]# ls
nginx-1.24.0.tar.gz


#安装依赖包

yum install -y gcc-c++
yum install -y zlib zib-devel
yum install -y pcre pcre-devel
yum install -y openssl openssl-devel


#解压

tar -zxvf nginx-1.24.0.tar.gz


#开始预编译

[root@yang-1 src]# cd nginx-1.24.0/
[root@yang-1 nginx-1.24.0]#
[root@yang-1 nginx-1.24.0]#./configure --with-http_ssl_module --with-http_v2_module --with-stream
[root@yang-1 nginx-1.24.0]# echo $?


#./configure预编译成功后,使用make进行编译,或直接执行make && make install

[root@yang-1 nginx-1.24.0]# make
[root@yang-1 nginx-1.24.0]# echo $?


#make编译成功后使用make install进行安装,把编译好的文件复制到系统中去

[root@yang-1 nginx-1.24.0]# make install
[root@yang-1 nginx-1.24.0]# echo $?


#查看所生产的配置文件

[root@yang-1 ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz


#启动服务

[root@yang-5 sbin]# cd /usr/local/nginx/sbin
[root@yang-5 sbin]# ./nginx
[root@yang-5 sbin]#
[root@yang-5 sbin]# ps aux |grep nginx
root      13376  0.0  0.0  46220  1160 ?        Ss   22:41   0:00 nginx: master process ./nginx
nobody    13377  0.0  0.0  48756  1992 ?        S    22:41   0:00 nginx: worker process
root      13379  0.0  0.0 112824   988 pts/0    S+   22:41   0:00 grep --color=auto nginx


#停止服务

[root@yang-5 sbin]# /usr/local/nginx/sbin/nginx -s stop