centos7上源码安装nginx-1.17.3.tar

2023-12-16 23:48

本文主要是介绍centos7上源码安装nginx-1.17.3.tar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、安装

1、手动建下载好的安装包放到linux服务器上

下载地址:http://nginx.org/download/;源码安装选择.tar.gz结尾的安装包,如http://nginx.org/download/nginx-1.17.3.tar.gz

2、解压安装包

tar -zvxf nginx-1.17.3.tar.gz

3、创建安装文件夹

mkdir /home/nginx

4、安装编译环境

yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel

5、源码安装软件时配置环境用,根据你的配置选项和你的系统情况生成makefile文件,为make做准备

./configure --prefix=/home/nginx

6、编译

make

7、安装

make install

 

二、测试安装

1、跳转到nginx的安装位置

cd /home/nginx/sbin

2、查看nginx是否启动(未启动)

[root@localhost sbin]# ps -ef|grep nginx
root       4100   1368  0 23:46 pts/0    00:00:00 grep --color=auto nginx

3、启动nginx

./nginx  或者  ./nginx -c /home/nginx/conf/nginx.conf

4、查看nginx是否启动(已启动,含主进程和后台进程)

[root@localhost sbin]# ps -ef|grep nginx
root       4102      1  0 23:48 ?        00:00:00 nginx: master process ./nginx
nobody     4103   4102  0 23:48 ?        00:00:00 nginx: worker process
root       4105   1368  0 23:49 pts/0    00:00:00 grep --color=auto nginx

5、访问nginx方式查看启动

curl http://127.0.0.1/

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

三、Nginx设置成服务并开机自动启动

1、添加服务到service

vim /lib/systemd/system/nginx.service

2、编写nginx.service中的内容

[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/home/nginx/sbin/nginx
ExecReload=/home/nginx/sbin/nginx -s reload
ExecStop=/home/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

3、添加启动文件

vim /etc/init.d/nginx

4、填写内容

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.1.17.3 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/home/nginx/sbin/nginx
nginx_config=/home/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];thenecho "nginx already running...."exit 1
fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL
}
# Stop nginx daemons functions.
stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo
}
# See how we were called.
case "$1" in
start)start;;
stop)stop;;
reload)reload;;
restart)stopstart;;
status)status $progRETVAL=$?;;
*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1
esac
exit $RETVAL

5、保存后设置文件的执行权限

chmod 777 /etc/init.d/nginx

6、启动或停止nginx(可能无法停止,因为守护进程存在)

/etc/init.d/nginx start
/etc/init.d/nginx stop

7、步骤4中的方式虽能启动,但是也不太方便,添加到服务中开机自启动。

chkconfig --add /etc/init.d/nginx

8、设置开机自启动

chkconfig nginx on

9、查看自启动服务列表

chkconfig --list

10、通过服务方式管理nginx,相关命令:

service nginx start
service nginx stop
service nginx restart

11、同时也可使用systemctl(管理systemd的资源Unit,即.service文件,兼容service命令)进行管理,常见命令:

# systemctl start nginx          启动服务

# systemctl stop nginx          停止服务

# systemctl restart nginx        重启服务

# systemctl status nginx   查看服务当前状态

# systemctl list-units --type=service      查看所有已启动的服务

这篇关于centos7上源码安装nginx-1.17.3.tar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/502347

相关文章

史上最全nginx详细参数配置

《史上最全nginx详细参数配置》Nginx是一个轻量级高性能的HTTP和反向代理服务器,同时也是一个通用代理服务器(TCP/UDP/IMAP/POP3/SMTP),最初由俄罗斯人IgorSyso... 目录基本命令默认配置搭建站点根据文件类型设置过期时间禁止文件缓存防盗链静态文件压缩指定定错误页面跨域问题

nginx负载均衡及详细配置方法

《nginx负载均衡及详细配置方法》Nginx作为一种高效的Web服务器和反向代理服务器,广泛应用于网站的负载均衡中,:本文主要介绍nginx负载均衡及详细配置,需要的朋友可以参考下... 目录一、 nginx负载均衡策略1.1 基本负载均衡策略1.2 第三方策略1.3 策略对比二、 nginx配置2.1

Android实现一键录屏功能(附源码)

《Android实现一键录屏功能(附源码)》在Android5.0及以上版本,系统提供了MediaProjectionAPI,允许应用在用户授权下录制屏幕内容并输出到视频文件,所以本文将基于此实现一个... 目录一、项目介绍二、相关技术与原理三、系统权限与用户授权四、项目架构与流程五、环境配置与依赖六、完整

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

Win安装MySQL8全过程

《Win安装MySQL8全过程》:本文主要介绍Win安装MySQL8全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Win安装mysql81、下载MySQL2、解压文件3、新建文件夹data,用于保存数据库数据文件4、在mysql根目录下新建文件my.ini

最详细安装 PostgreSQL方法及常见问题解决

《最详细安装PostgreSQL方法及常见问题解决》:本文主要介绍最详细安装PostgreSQL方法及常见问题解决,介绍了在Windows系统上安装PostgreSQL及Linux系统上安装Po... 目录一、在 Windows 系统上安装 PostgreSQL1. 下载 PostgreSQL 安装包2.

Nginx location匹配模式与规则详解

《Nginxlocation匹配模式与规则详解》:本文主要介绍Nginxlocation匹配模式与规则,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、环境二、匹配模式1. 精准模式2. 前缀模式(不继续匹配正则)3. 前缀模式(继续匹配正则)4. 正则模式(大

Maven如何手动安装依赖到本地仓库

《Maven如何手动安装依赖到本地仓库》:本文主要介绍Maven如何手动安装依赖到本地仓库问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载依赖二、安装 JAR 文件到本地仓库三、验证安装四、在项目中使用该依赖1、注意事项2、额外提示总结一、下载依赖登

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然