当前位置:首页 » 编程软件 » centos7nginx启动脚本

centos7nginx启动脚本

发布时间: 2022-10-03 17:24:27

⑴ 怎么在centos 6.5安装nginx

一、准备事项
(1) 因为nginx需要访问80端口所以请先关闭或者开放防火墙端口,和selinux
参考命令
关闭防火墙:
[root@local ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@local ~]# service iptables save
关闭selinux:
[root@local ~]# setenforce 0
[root@local ~]# vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled

(2) 如果用到域名请自行构建DNS服务
二、安装
(1) 因为nginx的运行需要安装pcre、zlib等软件包,因此我们进行安装
Pcre=Pcre Compatible Regular Expressions(中文pcre兼容正则表达式)
Yum配置请参考: http://www.linuxidc.com/Linux/2015-11/125332.htm
[root@local ~] yum -y install pcre* zlib* #或者进行编译安装
[root@local ~]# useradd -M -s /sbin/nologin nginx #创建nginx服务

启动用户
(3) 编译安装nginx,下载地址:http://nginx.org/en/download.html 此次安装为最新稳定版nginx-1.8.0
[root@local ~]# tar zxf nginx-1.8.0.tar.gz
[root@local ~]# cd nginx-1.8.0
[root@local nginx-1.8.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@local nginx-1.8.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.8.0 --with-http_stub_status_mole --with-http_ssl_mole #./configure –help 参数详解
[root@local nginx-1.8.0]# make
[root@local nginx-1.8.0]# make install

(4) 制作软连接
[root@local nginx-1.8.0]#ln –a /application/nginx-1.8.0/
/application/nginx

(5) 基本使用
#语法检查
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx –t
nginx: the configuration file /application/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.0/conf/nginx.conf test is successful
#启动服务
[root@local nginx-1.8.0]# /application/nginx/sbin/nginx
#端口检查
[root@local nginx-1.8.0]# netstat –lnt
#检查进程
[root@local nginx-1.8.0]# ps -ef | grep nginx #端口信息保存在
/application/nginx/logs/ nginx.pid 文件中
#通过端口查看占用进程
[root@local nginx-1.8.0]# lsof -i :80
#错误日志
/application/nginx/logs/error.log

三、编写nginx服务脚本
为了方便使用习惯,通过server 来启动、关闭、开启、重载nginx服务所以我们来编
写nginx的服务脚本(自己编写的脚本仅供参考!)
[root@local ~]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20
#description:Nginx Server Contorl Script
PROG="/application/nginx/sbin/nginx"
PIDF="/application/nginx/logs/nginx.pid"
ok=`echo -e "\e[1;31m [ok] \e[0m"`
no=`echo -e "\e[1;31m [no] \e[0m"`
detection=`/application/nginx/sbin/nginx -t 2>&1`
screen_1=`echo $detection | awk '{print $6,$7,$8}'`
screen_2=`echo $detection | awk '{print $13,$14,$15}'`
if [ "$screen_1" = "syntax is ok" ] && [ "$screen_2" = "test is successful" ];
then
case "$1" in
start)
$PROG
echo "Nginx Is starting state $ok"
;;
stop)
kill -s QUIT $(cat $PIDF)
echo "Nginx Is closing state $ok"
;;
restart)
$0 stop
$0 start
echo "Nginx Is to restart state $ok"
;;
reload)
kill -s HUP $(cat $PIDF)
echo "Nginx Is overloaded state $ok"
;;
*)
echo "Usage: $0 (start|stop|restart|reload)"
exit 1
esac
else
echo "Nginx check state $no "
echo "Please check the configuration file"
echo "$detection"
fi
exit 0

[root@local ~]# chmod +x /etc/init.d/nginx
[root@local ~]# chkconfig –add nginx #添加为系统服务
[root@local ~]# chkconfig nginx on

四、简单的nginx web站点
Nginx的默认站点目录,是安装目录下的html这里是(/application/nginx/html)
在主配置文件/application/nginx/conf/nginx.conf 中查看,对于重新部署web页面
只需将/application/nginx/html/中的index.html替换即可
主配置文件讲解

[root@local ~]# egrep -v "#|^$" /application/nginx/conf/nginx.conf
worker_processes 1; #指定Nginx开启的进程数
events { #设定Nginx的工作模式及连接数上线
worker_connections 1024;
}
http {
include mime.types; #主模块命令,实现对配置文件所有包含文件的设置
default_type application/octet-stream; #属于http核心模块命令,这里设
置类型为二进制流,也就是当文件类型未定义时使用这种方式,例如,没有配置php
环境时,nginx是不给予解析的,此时,用浏览器访问PHP文件就会出现下载窗口。
sendfile on; #用于高效文件传输模式
keepalive_timeout 65; 设置客户端请求头文件读取超时时间,如果超过这个时
间服务器会关闭该连接。
server { #定义虚拟主机开始的关键字
listen 80; #用于指定虚拟主机的服务端口
server_name localhost; 用于指定ip地址或者域名,多个域名用空格隔开
location / {
root html;
index index.html index.htm; #用于设定访问的默认首页
}
error_page 500 502 503 504 /50x.html;# 静态页面重定向服务器错误
页面,例如携程的网站崩溃出现的页面
location = /50x.html {
root html;
}
}
}

⑵ 为什么 centos 7 安装 nginx 后显示 Welcome to nginx on Fedora

安装环境为:最小化安装的centos7,关闭seliunx。最小化安装centos:关闭selinuxsed–i‘s/SELINUX=enforcing/SELINUX=disabled/g’/etc/selinux/config开始安装nginx1.7.8创建群组groupaddpilerccisnotfound解决方法:yuminstallgccgcc-c++如果有错误提示:./configure:error:.–without-http_rewrite_moleoption,,–with-pcre=option.解决方法:yuminstallpcre-devel如果有错误提示:./configure:error:.,,–with-openssl=option.解决方法:yuminstallopenssl-devel以上错误提示依次解决后:再一次的运行./configure--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_mole--with-http_ssl_mole--with-http_gzip_static_molemakemekeinstall编译参数解释:#指定运行权限的用户--user=www#指定运行的权限用户组--group=www#指定安装路径--prefix=/usr/local/nginx#支持nginx状态查询--with-http_stub_status_mole#开启ssl支持--with-http_ssl_mole#开启GZIP功能--with-http_gzip_static_mole因此要顺利的通过nginx编译安装必须安装的依赖关系有:yuminstallgcgccgcc-c++pcre-develzlib-developenssl-devel2、在centos7中为nginx的启动、重启、重载配置添加脚本nginx直接启动的方法:/usr/local/nginx/sbin/nginx但是不是很方便,因此使用下面的脚本来控制nginx的启动关闭重载更加合理一些。编辑文件:vim/usr/lib/systemd/system/nginx.service添加下面的脚本,注意路径![Unit]Description=nginx-=kill-sQUIT$MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.targetsystemctl的一些使用方法:systemctlis-enabledservicename.service#查询服务是否开机启动systemctlenablexxx.service#开机运行服务systemctldisablexxx.service#取消开机运行systemctlstartxxx.service#启动服务systemctlstopxxx.service#停止服务systemctlrestartxxx.service#重启服务systemctlreloadxxx.service#重新加载服务配置文件systemctlstatusxxx.service#查询服务运行状态systemctl--failed#显示启动失败的服务因此,添加上面脚本后,centos7中操作nginx的方法有systemctlis-enablednginx.service#查询nginx是否开机启动systemctlenablenginx.service#开机运行nginxsystemctldisablenginx.service#取消开机运行nginxsystemctlstartnginx.service#启动nginxsystemctlstopnginx.service#停止nginxsystemctlrestartnginx.service#重启nginxsystemctlreloadnginx.service#重新加载nginx配置文件systemctlstatusnginx.service#查询nginx运行状态systemctl--failed#显示启动失败的服务

⑶ nginx启动失败了,怎么解决centos7

你这个是安装nginx时出现错误了,你是通过yum安装的,还是apt-get?这两种方式安装会生成一些非原生的东西,比如说使用apt-get安装,它会生成两个配置文件,一个是原生的nginx.conf,还有一个叫user.conf吧,具体什么名忘了,是以前一个同事这么安装我看到的。就是说,你使用这样安装它会生成一些跟编译安装不一样的东西,如果这些东西里面有哪个不正确就会出错,建议你重新安装一下。如果你使用yum安装的,那么使用yum -e卸载重新再试一次。
不过我还是建议你使用编译安装,编译安装的方式不会生成那么多自己不知道的东西,全部都在一个文件夹下面,一个make&&make install就行了,你网上搜一下相关资料

⑷ 装了几次centos7了。每次配完nginx重启再开机开到一半就黑屏。在线等

发出来安装ngnix步骤
脚本安装的话注意下添加到服务的步骤看下是否有误把系统之前的服务搞没有了

⑸ 如何在 CentOS 7 用 cPanel 配置 Nginx 反向代理

第一步: 安装 EPEL 库
root@server1 [/usr]# yum -y install epel-release
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
* EA4: 66.23.237.210
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
epel-release noarch 7-5 extras 14 k

第二步: 安装 nDeploy 的 CentOS RPM 库
可以安装 nDeploy 的 CentOS RPM 库来安装我们所需的 nDeploy Web 类软件和 Nginx 插件
root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm
Loaded plugins: fastestmirror, tsflags, universal-hooks
nDeploy-release-centos-1.0-1.noarch.rpm | 1.7 kB 00:00:00
Examining /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm: nDeploy-release-centos-1.0-1.noarch
Marking /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package nDeploy-release-centos.noarch 0:1.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110

第三步:安装 nDeploy 和 Nginx nDeploy 插件
root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeploy
Loaded plugins: fastestmirror, tsflags, universal-hooks
epel/x86_64/metalink | 9.9 kB 00:00:00
epel | 4.3 kB 00:00:00
ndeploy | 2.9 kB 00:00:00
(1/4): ndeploy/7/x86_64/primary_db | 14 kB 00:00:00
(2/4): epel/x86_64/group_gz | 169 kB 00:00:00
(3/4): epel/x86_64/primary_db | 3.7 MB 00:00:02

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy noarch 2.0-11.el7 ndeploy 80 k
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
Installing for dependencies:
PyYAML x86_64 3.10-11.el7 base 153 k
libevent x86_64 2.0.21-4.el7 base 214 k
memcached x86_64 1.4.15-9.el7 base 84 k
python-inotify noarch 0.9.4-4.el7 base 49 k
python-lxml x86_64 3.2.1-4.el7 base 758 k

Transaction Summary
========================================================================================
Install 2 Packages (+5 Dependent packages)

通过以上这些步骤,我们完成了在我们的服务器上 Nginx 插件的安装。现在我们可以配置 Nginx 作为反向代理和为已有的 cPanel 用户账户创建虚拟主机,为此我们可以运行如下脚本。
第四步:启动 Nginx 作为默认的前端 Web 服务器,并创建默认的配置文件
root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enable
Modifying apache http and https port in cpanel

httpd restarted successfully.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_watcher.service to /usr/lib/systemd/system/ndeploy_watcher.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/ndeploy_backends.service to /usr/lib/systemd/system/ndeploy_backends.service.
ConfGen:: saheetha
ConfGen:: satest

你可以看到这个脚本将修改 Apache 的端口从 80 到另一个端口来让 Nginx 作为前端 Web 服务器,并为现有的 cPanel 用户创建虚拟主机配置文件。一旦完成,确认 Apache 和 Nginx 的状态。
Apache 状态:
root@server1 [/var/run/httpd]# systemctl status httpd
● httpd.service - Apache Web Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-01-18 06:34:23 UTC; 12s ago
Process: 25606 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 24760 (httpd)
CGroup: /system.slice/httpd.service
‣ 24760 /usr/local/apache/bin/httpd -k start

Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Starting Apache Web Server...
Jan 18 06:34:23 server1.centos7-test.com apachectl[25606]: httpd (pid 24760) already running
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.

Nginx 状态:
root@server1 [~]# systemctl status nginx
● nginx.service - nginx-nDeploy - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2016-01-17 17:18:29 UTC; 13h ago
Docs: http://nginx.org/en/docs/
Main PID: 3833 (nginx)
CGroup: /system.slice/nginx.service
├─ 3833 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─25473 nginx: worker process
├─25474 nginx: worker process
└─25475 nginx: cache manager process

Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Starting nginx-nDeploy - high performance web server...
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Started nginx-nDeploy - high performance web server.

Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听 http 端口 9999 和 https 端口 4430。请看他们的情况:
root@server1 [/usr/local/src]# netstat -plan | grep httpd
tcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 17270/httpd
tcp6 0 0 :::4430 :::* LISTEN 17270/httpd
tcp6 0 0 :::9999 :::* LISTEN 17270/httpd

root@server1 [/usr/local/src]# netstat -plan | grep nginx
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx: master
tcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx: master

为已有用户创建的虚拟主机的配置文件在 “/etc/nginx/sites-enabled”。 这个文件路径包含了 Nginx 主要配置文件。
root@server1 [/etc/nginx/sites-enabled]# ll | grep .conf
-rw-r--r-- 1 root root 311 Jan 17 09:02 saheetha.com.conf
-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf

一个域名的示例虚拟主机:
server {

listen 45.79.183.73:80;
#CPIPVSIX:80;

# ServerNames
server_name saheetha.com www.saheetha.com;
access_log /usr/local/apache/domlogs/saheetha.com main;
access_log /usr/local/apache/domlogs/saheetha.com-bytes_log bytes_log;

include /etc/nginx/sites-enabled/saheetha.com.include;

}

我们可以启动浏览器查看网站来确定 Web 服务器的工作状态。安装后,请阅读服务器上的 web 服务信息。
root@server1 [/home]# ip a | grep -i eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 45.79.183.73/24 brd 45.79.183.255 scope global dynamic eth0
root@server1 [/home]# nginx -v
nginx version: nginx/1.8.0

Nginx 将会为任何最新在 cPanel 中创建的账户创建虚拟主机。通过这些简单的的步骤,我们能够在一台 CentOS 7 / cPanel 的服务器上配置 Nginx 作为反向代理。
Nginx 作为反向代理的优势
便于安装和配置。
效率高、性能好。
防止 Ddos 攻击。
支持使用 .htaccess 作为 PHP 的重写规则。

⑹ 如何安装nginx

nginx
windows版
v1.13.3免费版http://www.ddooo.com/softdown/29113.htm
nginx
windows安装配置方法
第一步、安装方法
一、下载好后,把nginx
windows版软件解压到c盘根目录。
二、双击nginx.exe图标,可见黑窗口一闪而过,启动完毕。
三、按下win+R快捷键,输入cmd打开命令行。
四、命令行到nginx目录,输入nginx启动。(注,此方式命令行窗口无任何提示,且被锁定)
五、打开浏览器,输入http://127.0.0.1,如果看到下图片则安装成功。
六、以后启动软件直接双击图标即可。
七、启动后,默认情况下(无修改配置),可见到有两个nginx的进程,一个是master
process,一个是worker
processes测试。
第二步、配置方法
配置目标:能正常运行PHP脚本程序
大部分情况下,我们需要修改的配置文件只有一个,那就是nginx.conf,该文件位于conf目录下。具体配置项目为:
1.
server_tokens
off;
出于安全方面的考虑,最好是隐藏nginx版本号信息
2.
listen
8088;
8088为监听端口,根据需要可以填写其它端口号
3.
server_name
localhost;
localhost为服务器访问名称,也就是我们在浏览器里输入的那个url地址
4.
charset
utf-8;
字符集编码
5.
工作目录
将如下配置
修改为:
root
定义了工作空间,也就是我们php项目所在的目录。
加入index.php是为了让nginx能够识别php脚本,否则,在访问php文件时,会出现直接下载的情况。
6.
整合php
将location
~
\.php配置部分的注释全部去掉,最终配置如下:
注意这里面的$document_root变量,它对应的内容就是root参数值,如果我们没有定义root参数或者把root注释掉,在访问php的时候,页面上就会出现No
input
file
specified.提示。
7.
启动php-cgi
打开cmd命令窗口,切换到php的安装目录,执行php-cgi
-b
127.0.0.1:9000,即可启动php-cgi,启动完成后,cmd窗口切勿关闭,否则php-cgi也会被关掉的。
特别提醒:只有在开启php-cgi的情况下,nginx才能正常访问php。
8.
重启nginx
打开cmd命令窗口,切换到nginx所在目录,执行nginx
-s
reload即可重启nginx。其它相关nginx相关命令如下:
启动:start
nginx
停止:nginx
-s
stop
退出:nginx
-s
quit

⑺ centos 7 启动程序 带参数d 是什么意思

首先,系统貌似没有加 d 的参数,除非程序是你自己开发的特定程序,加d为特定参数。
linux 添加开机启动项的三种方法。
(1)编辑文件 /etc/rc.local
输入命令:vim /etc/rc.local 将出现类似如下的文本片段:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/init.d/mysqld start #mysql开机启动
/etc/init.d/nginx start #nginx开机启动
/etc/init.d/php-fpm start #php-fpm开机启动
/etc/init.d/memcached start #memcache开机启动
#在文件末尾(exit 0之前)加上你开机需要启动的程序或执行的命令即可(执行的程序需要写绝对路径,添加到系统环境变量的除外),如:
/usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf

(2)自己写一个shell脚本
将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。
(3)通过chkconfig命令设置
将启动文件cp到 /etc/init.d/或者/etc/rc.d/init.d/(前者是后者的软连接)下
vim 启动文件,文件前面务必添加如下三行代码,否侧会提示chkconfig不支持
#!/bin/sh 告诉系统使用的shell,所以的shell脚本都是这样
#chkconfig: 35 20 80 分别代表运行级别,启动优先权,关闭优先权,此行代码必须
#description: http server(自己随便发挥)//两行都注释掉!!!,此行代码必须
chkconfig --add 脚本文件名 操作后就已经添加了

⑻ centos7怎么编译安装nginx

安装环境为:最小化安装的centos7,关闭seliunx。
最小化安装centos:
关闭selinux
sed –i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

开始安装nginx1.7.8
创建群组
groupadd www
创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g www -M www
#下载最新版nginx
wget -C http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxvf nginx-1.7.8.tar.gz
#编译基本能运行的nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
make install

如果有错误提示:
./configure: error: C compiler cc is not found
解决方法:
yum install gcc gcc-c++

如果有错误提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre=<path> option.
解决方法:
yum install pcre-devel

如果有错误提示:
./configure: error: SSL moles require the OpenSSL library.
You can either do not enable the moles, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解决方法:
yum install openssl-devel

以上错误提示依次解决后:再一次的运行
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
meke install

编译参数解释:
#指定运行权限的用户
--user=www
#指定运行的权限用户组
--group=www
#指定安装路径
--prefix=/usr/local/nginx
#支持nginx状态查询
--with-http_stub_status_mole
#开启ssl支持
--with-http_ssl_mole
#开启GZIP功能
--with-http_gzip_static_mole

因此要顺利的通过nginx编译安装必须安装的依赖关系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2、在 centos7 中为nginx的启动、重启、重载配置添加脚本
nginx直接启动的方法:
/usr/local/nginx/sbin/nginx

但是不是很方便,因此使用下面的脚本来控制nginx的启动关闭重载更加合理一些。
编辑文件:vim /usr/lib/systemd/system/nginx.service 添加下面的脚本,注意路径 !
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl的一些使用方法:
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable xxx.service #开机运行服务
systemctl disable xxx.service #取消开机运行
systemctl start xxx.service #启动服务
systemctl stop xxx.service #停止服务
systemctl restart xxx.service #重启服务
systemctl reload xxx.service #重新加载服务配置文件
systemctl status xxx.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

因此,添加上面脚本后,centos7 中操作nginx的方法有
systemctl is-enabled nginx.service #查询nginx是否开机启动
systemctl enable nginx.service #开机运行nginx
systemctl disable nginx.service #取消开机运行nginx
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重启nginx
systemctl reload nginx.service #重新加载nginx配置文件
systemctl status nginx.service #查询nginx运行状态
systemctl --failed #显示启动失败的服务

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:944
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:741
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372