Nginx安装

CentOS安装Nginx

安装EPEL仓库

yum install epel-release

更新repo

yum update

 安装nginx

yum install nginx

验证安装 

 nginx -V

可以从Nginx官⽅仓库来安装

安装前置依赖 

yum install yum-utils

 添加nginx仓库

vi /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

 更新repo

yum update

安装nginx 

yum install nginx

 验证安装

nginx
curl -I 127.0.0.1

Ubuntu安装Nginx

更新仓库信息 

apt-get update

安装nginx

apt-get install nginx

验证安装

nginx -V

可以从Nginx官⽅仓库来安装

安装前置依赖 

apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

导⼊官⽅Nginx签名密钥

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

验证下载的⽂件中包含了正确的密钥

gpg --dry-run --quiet --no-keyring --import --import-options import-show
/usr/share/keyrings/nginx-archive-keyring.gpg

设置稳定版或者主线版的Nginx包

# 稳定版
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
 | sudo tee /etc/apt/sources.list.d/nginx.list

# 主线版
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
 | sudo tee /etc/apt/sources.list.d/nginx.list

 设置仓库优先级,优先使⽤Nginx官⽅仓库

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPinPriority: 900\n" \
 | sudo tee /etc/apt/preferences.d/99nginx

安装nginx 

apt update
apt install nginx

验证安装 

nginx
curl -I 127.0.0.1

源码编译安装

从源码编译安装的⽅式可以让我们⾃定义Nginx的安装⽬录、模块等,但是安装过程⽐较繁
琐,需要安装⼀些依赖库

安装PCRE库 

wget github.com/PCRE2Project/pcre2/releases/download/pcre2-10.42/pcre2-
10.42.tar.gz
tar -zxf pcre2-10.42.tar.gz
cd pcre2-10.42
./configure
make
sudo make install

安装zlib库 

wget http://zlib.net/zlib-1.2.13.tar.gz
tar -zxf zlib-1.2.13.tar.gz
cd zlib-1.2.13
./configure
make
sudo make install

安装OpenSSL库 

wget http://www.openssl.org/source/openssl-1.1.1t.tar.gz
tar -zxf openssl-1.1.1t.tar.gz
cd openssl-1.1.1t
./Configure darwin64-x86_64-cc --prefix=/usr
make
sudo make install

下载Nginx源码 

# 主线版
wget https://nginx.org/download/nginx-1.23.4.tar.gz
tar zxf nginx-1.23.4.tar.gz
cd nginx-1.23.4

# 稳定版
wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar zxf nginx-1.24.0.tar.gz
cd nginx-1.24.0

配置编译选项 

./configure
--sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-pcre=../pcre2-10.42
--with-zlib=../zlib-1.2.13
--with-http_ssl_module
--with-stream
--with-mail=dynamic
--add-module=/usr/build/nginx-rtmp-module
--add-dynamic-module=/usr/build/3party_module
参数(Parameter)
说明(Description)
--prefix=
指定安装⽬录
--sbin-path=
指定Nginx可执⾏⽂件
--conf-path=
指定配置⽂件位置
--pid-path=
指定pid⽂件位置
--error-log-path=
指定错误⽇志⽂件
--http-log-path=
指定HTTP⽇志⽂件
--user=
指定运⾏Nginx的⽤户
--group=
指定运⾏Nginx的组
--with-pcre=
指定PCRE库的位置
--with-pcre-jit
开启PCRE的JIT(Just-in-time compilation)⽀持
--with-zlib=        
指定zlib库的位置

Nginx的配置⽂件 

Nginx的配置⽂件是 nginx.conf ,⼀般位于 /etc/nginx/nginx.conf .可以使⽤ nginx -t 来查看配置⽂件的位置和检查配置文件是否正确。 

nginx -t

你可能感兴趣的:(nginx,nginx,linux,运维)