Nginx的安装-Linux

发布时间 2023-10-23 21:00:47作者: 进城民工

下载地址

image

#如果没有gcc环境,需要安装gcc:
[root@localhost local]# yum install gcc-c++ -y
#安装依赖包
[root@localhost local]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 进入文件夹
[root@localhost local]# cd  /usr/local
#在线下载或者上传已下载安装包
[root@localhost local]# wget http://nginx.org/download/nginx-1.22.1.tar.gz
#解压安装包
[root@localhost local]# tar -xvf nginx-1.22.1.tar.gz 
#解压之后不需要重新命名直接进去解压目录
#进入nginx-1.22.1目录 
[root@localhost local]# cd /usr/local/nginx-1.22.1
#执行配置命令
#↓↓↓↓参数说明↓↓↓↓
#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
[root@localhost nginx-1.22.1]# ./configure --prefix=/nginx \
--conf-path=/nginx/conf/nginx.conf  \
--error-log-path=/nginx/logs/error.log \
--pid-path=/nginx/logs/nginx.pid  \
--http-log-path=/nginx/logs/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-stream \
--with-stream_ssl_preread_module 
#执行make命令
[root@localhost nginx-1.22.1]# make
#执行make install命令 
[root@localhost nginx-1.22.1]# make install
#切换到sbin目录
[root@localhost nginx-1.22.1]# cd /usr/local/nginx/sbin
#启动验证
[root@localhost sbin]# ./nginx
#查看nginx进程,存在下面记录,说明启动成功
[root@localhost sbin]# ps -ef | grep nginx
root      34692      1  0 20:16 ?        00:00:00 nginx: master process ./nginx
#指定配置启动
[root@localhost sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
#编辑配置文件/usr/local/nginx/conf/nginx.conf
#也可以通过工具下载到本地进行编辑后上传
[root@localhost sbin]# vi /usr/local/nginx/conf/nginx.conf
#指定配置重启
[root@localhost sbin]# ./nginx -s reload -c /usr/local/nginx/conf/nginx.conf