zypper install curl ca-certificates gpg2
zypper addrepo --gpgcheck --type yum --refresh --check 'http://nginx.org/packages/sles/$releasever_major' nginx-stable
zypper addrepo --gpgcheck --type yum --refresh --check 'http://nginx.org/packages/mainline/sles/$releasever_major' nginx-mainline
curl -o /tmp/nginx_signing.key https://nginx.org/keys/nginx_signing.key
gpg --with-fingerprint /tmp/nginx_signing.key
rpmkeys --import /tmp/nginx_signing.key
zypper install -y nginx
查看版本列表:
zypper search -xs nginx
安装指定版本:
zypper install -y nginx=版本号
示例:
zypper install -y nginx=1.24.0
yum install -y yum-utils
vim /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
yum-config-manager --enable nginx-mainline
yum install -y nginx
查看版本列表:
yum --showduplicates list nginx
安装指定版本:
yum install -y nginx-版本号
示例:
yum install -y nginx-1.24.0-1.el7.ngx
/etc/nginx
/usr/sbin/nginx
wget https://nginx.org/download/nginx-1.26.0.tar.gz
tar zxvf nginx-1.26.0.tar.gz
cd nginx-1.26.0
./configure --prefix=/opt/nginx/1.26.0 --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
其中
--prefix=/opt/nginx/1.26.0
为指定 nginx 的安装目录,--user=nginx
为指定运行 nginx 的用户,--group=nginx
为指定运行 nginx 的用户组,其他参数说明参数可以通过./configure --help
命令查看;此处示例安装模块较多,实际安装时按需求安装模块即可
按上述参数编译时,需安装如下依赖:
zlib
和 zlib-devel
openssl
和 openssl-devel
pcre
和 pcre-devel
libxml2
和 libxml2-devel
libxslt
和 libxslt-devel
gd
和 gd-devel
gperftools
yum 安装示例:
yum install -y zlib zlib-devel openssl openssl-devel pcre pcre-devel libxml2 libxml2-devel libxslt libxslt-devel gd-devel gperftools
cd nginx-1.26.0
make
第一次安装时还需要执行:
make install
/opt/nginx/1.26.0/sbin/nginx -c /opt/nginx/1.26.0/conf/nginx.conf
其中
/opt/nginx/1.26.0
为安装目录;此处示例在编译时指定了用户及用户组,因此需要切换至指定用户运行 nginx
参考资料:
https://nginx.org/download/nginx-1.26.0.zip
解压安装包
解压安装包至安装目录
运行 exe 文件
直接运行 exe 文件即可启动 Nginx