Centos安装Nginx

1、下载Nginx安装包

快速下载:wget http://nginx.org/download/nginx-1.18.0.tar.gz

官网下载:http://nginx.org/en/download.html

2、安装相关依赖

安装或更新gcc-c++ 依赖

yum -y install gcc gcc-c++ autoconf automake make

否则在安装过程中会报错如下:

./configure: error: C compiler cc is not found

安装或更新pcre、openssl

yum -y install pcre-devel

yum -y install openssl openssl-devel

否则在安装过程中会报错如下:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

安装或更新常用解压或打包工具

yum install -y zip unzip

3、解压Nginx安装包

# 解压到当前目录
tar zxvf nginx-1.18.0.tar.gz

4、配置安装运行目录

# 进入nginx解压目录下
cd /usr/local/nginx/nginx-1.18.0

# 配置安装运行命令
./configure --prefix=/usr/local/nginx/nginx

5、执行编译安装

make && make install 

6、启动Nginx

# 进入到运行目录
cd /usr/local/nginx/nginx
# 启动Nginx并指定配置文件 -t 测试配置文件是否正确
./sbin/nginx -c conf/nginx.conf
# 停止Nginx -s quit(等待进程处理完毕进行关闭)
./sbin/nginx -s stop
# 重启
./sbin/nginx -s reload

 默认监听80端口,访问测试即可

http://IP/

 

posted @ 2022-12-15 12:07  阿尔法哲  阅读(89)  评论(0编辑  收藏  举报