Centos7上源码编译安装Nginx的方法总结

58 篇文章 1 订阅

Centos7上源码编译安装Nginx方法

源码编译安装

官网下载,然后用XFTP上传到root目录
也可以使用命令

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

在这里插入图片描述
解压文件

tar -zxvf nginx-1.18.0.tar.gz

然后用yum安装依赖项

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

如果没装以上相关的依赖,会在./configure过程中出现各种错误

执行

./configure

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

再输入make命令生成二进制文件,屏幕会出现一堆命令,最后如下图所示

在这里插入图片描述

然后输入make install,把相关文件拷贝到对应的目录中,默认是/usr/local/nginx

配置nginx服务启动脚本

cd /etc/systemd/system
vi nginx.service

将以下内容复制到nginx.service里保存退出,以下内容,我是从官方yum安装后的service里面复制修改的

[UNIT]

Deion=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network-online.target remote-fs.target nss-lookup.target

Wants=network-online.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

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

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

[Install]

WantedBy=multi-user.target

然后将nginx设置为开机启动

systemctl enable nginx

在这里插入图片描述
启动nginx

systemctl start nginx.service

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值