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

相关文章

ESP32 esp-idf esp-adf环境安装及.a库创建与编译

简介 ESP32 功能丰富的 Wi-Fi & 蓝牙 MCU, 适用于多样的物联网应用。使用freertos操作系统。 ESP-IDF 官方物联网开发框架。 ESP-ADF 官方音频开发框架。 文档参照 https://espressif-docs.readthedocs-hosted.com/projects/esp-adf/zh-cn/latest/get-started/index

Linux 安装、配置Tomcat 的HTTPS

Linux 安装 、配置Tomcat的HTTPS 安装Tomcat 这里选择的是 tomcat 10.X ,需要Java 11及更高版本 Binary Distributions ->Core->选择 tar.gz包 下载、上传到内网服务器 /opt 目录tar -xzf 解压将解压的根目录改名为 tomat-10 并移动到 /opt 下, 形成个人习惯的路径 /opt/tomcat-10

VMware9.0详细安装

双击VMware-workstation-full-9.0.0-812388.exe文件: 直接点Next; 这里,我选择了Typical(标准安装)。 因为服务器上只要C盘,所以我选择安装在C盘下的vmware文件夹下面,然后点击Next; 这里我把√取消了,每次启动不检查更新。然后Next; 点击Next; 创建快捷方式等,点击Next; 继续Cont

vcpkg安装opencv中的特殊问题记录(无法找到opencv_corexd.dll)

我是按照网上的vcpkg安装opencv方法进行的(比如这篇:从0开始在visual studio上安装opencv(超详细,针对小白)),但是中间出现了一些别人没有遇到的问题,虽然原因没有找到,但是本人给出一些暂时的解决办法: 问题1: 我在安装库命令行使用的是 .\vcpkg.exe install opencv 我的电脑是x64,vcpkg在这条命令后默认下载的也是opencv2:x6

【服务器运维】CentOS6 minimal 离线安装MySQL5.7

1.准备安装包(版本因人而异,所以下面的命令中版本省略,实际操作中用Tab自动补全就好了) cloog-ppl-0.15.7-1.2.el6.x86_64.rpmcpp-4.4.7-23.el6.x86_64.rpmgcc-4.4.7-23.el6.x86_64.rpmgcc-c++-4.4.7-23.el6.x86_64.rpmglibc-2.12-1.212.el6.x86_64.r

【服务器运维】CentOS7 minimal 离线安装 gcc perl vmware-tools

0. 本机在有网的情况下,下载CentOS镜像 https://www.centos.org/download/ 1. 取出rpm 有的情况可能不需要net-tools,但是如果出现跟ifconfig相关的错误,就把它安装上。另外如果不想升级内核版本的话,就找对应内核版本的rpm版本安装 perl-Time-Local-1.2300-2.el7.noarch.rpmperl-Tim

Windows/macOS/Linux 安装 Redis 和 Redis Desktop Manager 可视化工具

本文所有安装都在macOS High Sierra 10.13.4进行,Windows安装相对容易些,Linux安装与macOS类似,文中会做区分讲解 1. Redis安装 1.下载Redis https://redis.io/download 把下载的源码更名为redis-4.0.9-source,我喜欢跟maven、Tomcat放在一起,就放到/Users/zhan/Documents

Ubuntu20.04离线安装Docker

1.下载3个docker离线安装包,下载网址: https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/ 2.把3个离线安装包拷贝到ubuntu本地执行以下命令 sudo dpkg -i containerd.io_1.4.6-1_amd64.deb sudo dpkg -i docker-ce-c

springboot家政服务管理平台 LW +PPT+源码+讲解

3系统的可行性研究及需求分析 3.1可行性研究 3.1.1技术可行性分析 经过大学四年的学习,已经掌握了JAVA、Mysql数据库等方面的编程技巧和方法,对于这些技术该有的软硬件配置也是齐全的,能够满足开发的需要。 本家政服务管理平台采用的是Mysql作为数据库,可以绝对地保证用户数据的安全;可以与Mysql数据库进行无缝连接。 所以,家政服务管理平台在技术上是可以实施的。 3.1

Windows中,.net framework 3.5安装

安装.net framework,目前已知2种方法,如下: 一、在MSDN下载对应的安装包,安装,这种可能无法安装成功,概率很大,不成功使用第二种方法,基本上没问题。 二、win8/8.1/10 下安装 .net framework 3.5.1: 1. 打开 win8/8.1/10 安装盘(这里指系统安装镜像文件),提取 sources\sxs 文件夹到 X:\sources\sxs (X代