centos安装和升级nginx

---------------------20230214 升级 nginx-1.23.3--------------------------

没有rpm包的情况下升级ngixn

下载依赖rpm 包到本地

yum install --downloadonly --downloaddir=.  gcc gcc-c++ autoconf automake make 
yum install --downloadonly --downloaddir=. pcre-devel  zlib zlib-devel openssl openssl-devel

安装rpm 

下载 nginx: download 解压 tar.gz

nginx -V 查看安装配置

[root@localhost nginx]# nginx -V
nginx version: nginx/1.23.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --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-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --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'

cd 解压后目录

 覆盖安装即可

./configure  【nginx -V  输出 configure arguments:后的内容】

make
make install
systemctl daemon-reload
systemctl restart nginx

---------------------20220526 升级--------------------------

 nginx 下载地址,可查看最新包 

Index of /packages/centos/7/x86_64/RPMS/

ng​​​​​​​Index of /packages/ (nginx.org)https://nginx.org/packages/​​​​​​centos7使用yum安装指定版本nginx_52 IT的博客-CSDN博客_yum安装nginx指定版本


 

下载本地

yum install --downloadonly --downloaddir=.  nginx....
 

---------------------20210809 升级--------------------------

rpm下载地址

Index of /packages/rhel/7/x86_64/RPMS/

#先下载nginx的rpm包
# 再执行 rpm -Uvh nginx-1.12***
# 升级后
[root@test soft]# rpm -qa|grep nginx

参考 利用 yum 命令和 rpm 命令升级 Nginx 或者安装最新版本 Nginx - morgan363 - 博客园

---------------------20210415--------------------------

nginx: Linux packages

配置yum源

yum install nginx

systemctl start nginx

---------------------20210415--------------------------

一、安装依赖

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

若没有安装编译相关的包则:

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

二、获取源码

  # wget http://nginx.org/download/nginx-1.12.2.tar.gz

  # tar -zxvf nginx-1.12.2.tar.gz 

  # cd nginx-1.12.2.tar.gz

三、编译安装

$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module

支持https的命令:

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module

然后:

make 

make install

四、相关命令

进入安装目录中,

命令: cd /usr/local/nginx/sbin

启动,关闭,重启,命令:

./nginx 启动

./nginx -s stop 关闭

./nginx -s reload  ##重新加载配置文件

./nginx -c nginx.conf           ##指定配置文件启动

查看nginx进程是否启动:   ps -ef | grep nginx

查看已安装模块 :  $ /usr/local/nginx/sbin/nginx -V

五、配置https,大致步骤:生成私钥,生成证书签署请求,并获得证书 

这里使用的是阿里云的免费证书,期限为1年,申请地址在此

在 nginx 目录新建 cert 文件夹存放证书文件。

$ cd /usr/local/nginx
$ mkdir cert

将这两个文件上传至服务器的 cert 目录里。

Nginx.conf 配置:

编辑 /usr/local/nginx/conf/nginx.conf 配置文件:

配置 https server。注释掉之前的 http server 配置,新增 https server:

server {
    # 服务器端口使用443,开启ssl, 这里ssl就是上面安装的ssl模块
    listen       443 ssl;
    # 域名,多个以空格分开
    server_name  hack520.com www.hack520.com;
    
    # ssl证书地址
    ssl_certificate     /usr/local/nginx/cert/ssl.pem;  # pem文件的路径
    ssl_certificate_key  /usr/local/nginx/cert/ssl.key; # key文件的路径
    
    # ssl验证相关配置
    ssl_session_timeout  5m;    #缓存有效期
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;    #加密算法
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    #安全链接可选的加密协议
    ssl_prefer_server_ciphers on;   #使用服务器端的首选算法

    location / {
        root   html;
        index  index.html index.htm;
    }
}

将 http 重定向 https。

server {
    listen       80;
    server_name  hack520.com www.hack520.com;
    return 301 https://$server_name$request_uri;
}

重启验证

参考:

nginx下载安装_baidu_38558076的博客-CSDN博客_nginx下载

LINUX安装nginx详细步骤_大蛇王的博客-CSDN博客_linux安装nginx

http://sunbingbing.cn/linux%E4%B8%8B%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85pcre%E5%BA%93/

linux下Zlib的安装与使用_九师兄的博客-CSDN博客_linux zlib

https://www.hack520.com/481.html

编译安装Nginx,配置使用HTTPS - 卢伸乐 - 博客园

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值