1. 从官网下载nginx源代码文件:https://nginx.org/download/nginx-1.18.0.tar.gz

2. 登录服务器,通过终端管理工具将文件上传到服务器

3. 配置好yum源,安装依赖

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

4. 解压缩文件,并进入解压出来的文件夹

tar zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0

5. 创建安装目录

mkdir /usr/local/nginx

6. 配置nginx的安装选项

./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/local/nginx/sbin \

--conf-path=/usr/local/nginx/conf/nginx.conf \

--error-log-path=/usr/local/nginx/logs/error.log \

--pid-path=/usr/local/nginx/nginx.pid \

--with-stream \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--with-pcre \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_v2_module

7. 开始安装

make && make install

8. 启动nginx

cd /usr/local/nginx

ls           # 查看一下当前目录下的文件

./sbin -c conf/nginx.conf

9. 检查是否有nginx进程

ps -ef | grep nginx

10. 常用命令

检查配置文件格式有无错误:

/usr/local/nginx/sbin -t

以指定配置文件启动:

/usr/local/nginx/sbin -c /usr/local/nginx/conf/nginx.conf

重新加载配置文件:

/usr/local/nginx/sbin -s reload

停止:

/usr/local/nginx/sbin -s stop

重启:

/usr/local/nginx/sbin -s reopen

最后:如果要修改nginx的配置文件,建议在修改之前先对文件进行备份,方便异常之后进行回退。

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐