Linux下Nginx编译安装后的开机自启动设置

简介: Linux下Nginx编译安装后的开机自启动设置

一、查看当前Nginx启动状态

[root@node1 sbin]# ps -ef |grep nginx
root      39424      1  0 14:01 ?        00:00:00 nginx: master process ./nginx
nobody    39425  39424  0 14:01 ?        00:00:00 nginx: worker process
root      40313   1884  0 15:41 pts/0    00:00:00 grep --color=auto nginx

二、而配置Nginx相关服务文件

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

三 、设置nginx命令

[root@node1 sbin]# cat  ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH={
   mathJaxContainer[0]}HOME/bin:/usr/local/nginx/sbin


export PATH
[root@node1 sbin]# source ~/.bash_profile 
[root@node1 sbin]# nginx -v
nginx version: nginx/1.18.0
[root@node1 sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

四、设置开机启动

root@node1 ~]# systemctl enable --now  nginx.service
[root@node1 ~]# ps -ef |grep nginx
root        879      1  0 16:17 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody      881    879  0 16:17 ?        00:00:00 nginx: worker process
root       1738   1645  0 16:20 pts/0    00:00:00 grep --color=auto nginx
[root@node1 ~]#

五、测试开机启动

[root@node1 ~]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-05-08 16:17:54 CST; 45s ago
  Process: 872 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 879 (nginx)
    Tasks: 2 (limit: 12404)
   Memory: 2.5M
   CGroup: /system.slice/nginx.service
           ├─879 nginx: master process /usr/local/nginx/sbin/nginx
           └─881 nginx: worker process

May 08 16:17:54 node1 systemd[1]: Starting nginx...
May 08 16:17:54 node1 systemd[1]: Started nginx.
相关文章
|
1天前
|
Linux C语言 虚拟化
VM和Linux的安装
VM和Linux的安装
|
1天前
|
关系型数据库 MySQL Linux
【菜鸟版】 Linux 安装 MySql 5.7
【菜鸟版】 Linux 安装 MySql 5.7
9 2
|
1天前
|
存储 Linux Android开发
Volatility3内存取证工具安装及入门在Linux下的安装教程
Volatility 是一个完全开源的工具,用于从内存 (RAM) 样本中提取数字工件。支持Windows,Linux,MaC,Android等多类型操作系统系统的内存取证。针对竞赛这块(CTF、技能大赛等)基本上都是用在Misc方向的取证题上面,很多没有听说过或者不会用这款工具的同学在打比赛的时候就很难受。以前很多赛项都是使用vol2.6都可以完成,但是由于操作系统更新,部分系统2.6已经不支持了,如:Win10 等镜像,而Volatility3是支持这些新版本操作系统的。
|
2天前
|
关系型数据库 MySQL Linux
mysql在linux下安装
mysql在linux下安装
15 3
|
2天前
|
Linux 开发工具
linux下安装Anaconda3
linux下安装Anaconda3
10 1
|
10月前
|
应用服务中间件 Linux Shell
设置Nginx开机自动启动(centos6.8上亲测可用)
设置Nginx开机自动启动(centos6.8上亲测可用)
|
Linux 应用服务中间件 nginx
|
30天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
87 0
|
30天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
86 0
|
4天前
|
Java Serverless 应用服务中间件
Serverless 应用引擎产品使用合集之Web函数启动的Spring Boot项目可以通过什么方式配置Nginx
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。