Linux环境搭建~Nginx

Administrator
发布于 2020-12-05 / 974 阅读 / 0 评论 / 0 点赞

Linux环境搭建~Nginx

官网:https://nginx.org/

系统:CentOS 7.8

Nginx版本:1.18.0


一、安装前的准备

Nginx的安装需要确定Linux安装相关的几个库,否则配置和编译会出现错误

1. 进入目录

cd /usr/local/src/

2. 一次性安装

yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel -y

3. 分开安装

进行判断是否已安装,再进行安装

  • gcc 编译器
yum list installed | grep gcc
yum install gcc -y
  • openssl 库
yum list installed | grep openssl
yum install openssl openssl-devel -y
  • pcre 库
yum list installed | grep pcre
yum install pcre pcre-devel -y
  • zlib 库
yum list installed | grep zlib
yum install zlib zlib-devel -y

二、安装 Nginx

1. 下载、解压nginx

下载地址:https://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

2. 编译、安装

注意:如果要SSL,就得加上 http_ssl_module模块

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

三、配置

1. 进入nginx

后面的命令基于当前目录

cd /usr/local/nginx

2. 启动

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

3. 查看nginx.conf配置

cat ./conf/nginx.conf

4. 查看config 配置是否正确

./sbin/nginx -t

5. 热重载配置

./sbin/nginx -s reload

6. 判断是否启动

浏览器访问ip出现下面页面,就是成功了
image.png


评论