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

相关文章

Python中win32包的安装及常见用途介绍

《Python中win32包的安装及常见用途介绍》在Windows环境下,PythonWin32模块通常随Python安装包一起安装,:本文主要介绍Python中win32包的安装及常见用途的相关... 目录前言主要组件安装方法常见用途1. 操作Windows注册表2. 操作Windows服务3. 窗口操作

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

Nginx 重写与重定向配置方法

《Nginx重写与重定向配置方法》Nginx重写与重定向区别:重写修改路径(客户端无感知),重定向跳转新URL(客户端感知),try_files检查文件/目录存在性,return301直接返回永久重... 目录一.try_files指令二.return指令三.rewrite指令区分重写与重定向重写: 请求

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根