centos7系统下nginx安装并配置开机自启动操作
2023-09-14 09:07:52 时间
准备工作
我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库
1
2
3
4
5
6
7
8
9
10
11
|
yum install wget gcc gcc -c ++ pcre -devel zlib -devel ##创建工作目录并进入工作目录 mkdir -p /z/nginx && cd /z/nginx ##获取nginx最新的安装包 ##解压缩 tar zxvf nginx-1.11.10.tar.gz ##进入目录 cd nginx-1.11.10 ##检测系统配置, 生成make相关文件 ./configure |
./configure执行成功会输出以下信息
nginx的安装位置,以及文件路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library 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" |
编译并安装
1
|
make && make install |
创建nginx启动命令脚本
1
|
vi /etc/init.d/nginx |
插入以下内容, 注意修改PATH和NAME字段, 匹配自己的安装路径 (这段是从网上copy的)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#! /bin/bash # chkconfig: - 85 15 PATH=/usr/local/nginx DESC= "nginx daemon" NAME=nginx DAEMON= $PATH /sbin/ $NAME CONFIGFILE= $PATH /conf/ $NAME .conf PIDFILE= $PATH /logs/ $NAME .pid SCRIPTNAME=/etc/init.d/ $NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0 |
设置执行权限
1
|
chmod a+x /etc/init.d/nginx |
注册成服务
1
|
chkconfig - -add nginx |
设置开机启动
1
|
chkconfig nginx on |
重启, 查看nginx服务是否自动启动
1
2
|
shutdown -h 0 -r netstat -apn |grep nginx |
对nginx服务执行停止/启动/重新读取配置文件操作
1
2
3
4
5
6
7
8
|
#启动nginx服务 systemctl start nginx.service #停止nginx服务 systemctl stop nginx.service #重启nginx服务 systemctl restart nginx.service #重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效) systemctl reload nginx.service |
以上所述是小编给大家介绍的centos7系统下nginx安装并配置开机自启动操作
相关文章
- 使用docker安装centos7并挂载主机目录
- centos7下memcached的安装配置
- centos7: vsftpd安装及启动: ftp配置(以虚拟用户为例)
- Centos7 squid安装与配置
- Centos7 k8s v1.5.2二进制部署安装-交付jenkins到k8s集群
- Centos7部署FastDFS(V6.01)集群
- Centos7安装部署openstack----基础服务安装
- CentOS7 64位下MySQL5.7安装与配置
- CentOS7 yum 安装与配置MySQL5.7
- 【问题解决方案】CentOS7替换yum的问题:使用yum makecache出现File contains no section headers
- Centos7安装部署openstack--Networking 网络服务(计算节点)
- Centos7 KVM安装部署
- Linux centos7安装nfs及服务端配置
- centos7 keepalived安装记录
- centos7最小化安装环境配置
- centos7和centos6通过yum安装JDK1.8
- centos7安装Logwatch配合msmtp邮件客户端发送服务器监控分析日志
- centos7下jenkins的几种安装方式(yum,rpm,war包,docker镜像)
- Linux centos7虚拟机安装Oracle11g完全教程
- Linux 安装及配置CentOS7
- Centos7 安装 Nginx
- Centos7和Windows下安装并配置 Zookeeper
- Centos7安装和配置JDK1.8版本
- CentOS7安装CDH(十三):CDH资源池配置
- CentOS7安装CDH(七):CDH集群Hadoop的HA配置
- Centos7安装docker