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