Centos7.9服务器编译安装Nginx1.24.0和php8.3

Centos7.9服务器编译安装Nginx1.24.0和php8.3

服务器nginx原版本有安全漏洞,需要升级,由于原始是yum源安装,通过yum直接升级,无法正常升级完成,故而需要卸载yum源,重新编译安装。

1、查看原来nginx版本,ps查看原来nginx进程,运行状态:

ps aux | grep nginx
​
root       1284  0.0  0.0  42264   244 ?        Ss    2023   0:00 nginx: master process /usr/sbin/nginx
nginx      1285  0.0  0.0  44352   816 ?        S     2023   0:00 nginx: worker process
nginx      1286  0.0  0.0  44352   836 ?        S     2023   0:00 nginx: worker process
nginx      1287  0.0  0.0  44352   824 ?        S     2023   0:00 nginx: worker process
nginx      1288  0.0  0.0  44352   704 ?        S     2023   0:00 nginx: worker process
nginx      1289  0.0  0.0  44352   888 ?        S     2023   0:00 nginx: worker process
nginx      1290  0.0  0.0  44352   868 ?        S     2023   0:00 nginx: worker process
nginx      1291  0.0  0.0  44352   680 ?        S     2023   0:00 nginx: worker process
nginx      1292  0.0  0.0  44352   804 ?        S     2023   0:00 nginx: worker process
root     106491  0.0  0.0 112816   980 pts/0    S+   15:35   0:00 grep --color=auto nginx
​

查看nginx版本号为1.20:

  • 16
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是centos7.9编译安装nginx的步骤: 1. 安装编译nginx所需的依赖库: ``` yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxslt libxslt-devel gd gd-devel perl perl-devel perl-ExtUtils-Embed ``` 2. 下载nginx源码包: 可以到官网(https://nginx.org/en/download.html)下载最新的稳定版nginx源码包。 3. 解压源码包: ``` tar zxvf nginx-xxx.tar.gz ``` 4. 进入nginx源码目录,执行以下命令进行编译安装: ``` ./configure --with-http_stub_status_module --with-http_ssl_module make && make install ``` 其中,--prefix参数指定nginx安装目录,--with-http_stub_status_module参数启用状态页模块,--with-http_ssl_module参数启用SSL加密支持。 5. 配置nginx: 进入/usr/local/nginx/conf目录,编辑nginx.conf文件,进行配置。这里给出一个简单的配置文件示例: ``` user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } server { listen 443 ssl; server_name localhost; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } } ``` 其中,listen参数指定监听端口,server_name参数指定域名,root参数指定网站根目录,ssl_certificate和ssl_certificate_key参数指定SSL证书和私钥文件路径。 6. 启动nginx: 进入/usr/local/nginx/sbin目录,执行以下命令启动nginx: ``` ./nginx ``` 7. 检查nginx是否启动成功: 执行以下命令查看nginx进程是否存在: ``` ps -ef | grep nginx ``` 执行以下命令检查nginx监听的端口是否打开: ``` netstat -tlnp | grep nginx ``` 如果输出类似以下内容,则说明nginx已经成功安装并启动: ``` tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN xxxx/nginx tcp 0 0 :::443 :::* LISTEN xxxx/nginx ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值