GVKun编程网logo

centos7 安装与配置 nginx1.11,开机启动

28

如果您想了解centos7安装与配置nginx1.11,开机启动的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析(centos7)nginx手动启动,关闭,开机自启、centOS6.5Ngin

如果您想了解centos7 安装与配置 nginx1.11,开机启动的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析(centos7) nginx 手动启动,关闭,开机自启、centOS 6.5 Nginx 配置开机启动、centos 67安装nginx 110 centos7 nginx php centos官网 centos下、CentOS 7 设置Nginx开机启动的各个方面,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

centos7 安装与配置 nginx1.11,开机启动

centos7 安装与配置 nginx1.11,开机启动

1、官网下载安装包

    http://nginx.org/en/download.html,选择适合 Linux 的版本,这里选择最新的版本,下载到本地后上传到服务器或者 centos 下直接 wget 命令下载。

20161013211159.png

    切换到 /usr/local 目录,下载软件包

1
2
# cd /usr/local
# wget http://nginx.org/download/nginx-1.11.5.tar.gz

2、安装 nginx

先执行以下命令,安装 nginx 依赖库,如果缺少依赖库,可能会安装失败,具体可以参考文章后面的错误提示信息。

1
2
3
4
5
6
7
# yum install gcc-c++
# yum install pcre
# yum install pcre-devel
# yum install zlib 
# yum install zlib-devel
# yum install openssl
# yum install openssl-devel

    解压安装包

1
# tar -zxvf nginx-1.11.5.tar.gz

    nginx 被解压到了 /usr/local/nginx-1.11.5 目录下(不要把压缩包解压到 /usr/local/nginx 目录下,或者将解压后的目录重命名为 nginx,因为 nginx 会默认安装到 /usr/local/nginx 目录下),切换到 nginx-1.11.5 / 目录

1
# cd /usr/local/nginx-1.11.5/

    执行# ./configure

1
# ./configure

    该操作会检测当前系统环境,以确保能成功安装 nginx,执行该操作后可能会出现以下几种提示:

    checking for OS

     + Linux 3.10.0-123.el7.x86_64 x86_64

    checking for C compiler ... not found

    ./configure: error: C compiler cc is not found

    如果出现以上错误提示信息,执行 yum install gcc-c++ 安装 gcc,

    ./configure: error: the HTTP rewrite module requires the PCRE library.

    You can either disable the module by using --without-http_rewrite_module

    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.

    如果出现上面提示,表示缺少 PCRE 库

    ./configure: error: the HTTP gzip module requires the zlib library.

    You can either disable the module by using --without-http_gzip_module

    option, or install the zlib library into the system, or build the zlib library

    statically from the source with nginx by using --with-zlib=<path> option.

    如果出现以上提示,表示缺少 zlib 库

 

    如果没有出现./configure: error 提示,表示当前环境可以安装 nginx,执行 make 和 make install 编译 nginx

1
2
# make
# make install

    没有出错的话,表示 nginx 已经成功安装完成,默认安装位置为 /usr/local/nginx, 之前的 /usr/local/nginx-1.11.5 / 可以删除掉了。

    如果出现 cp: ''conf/koi-win'' and ''/usr/local/nginx/conf/koi-win'' are the same file,可能是你把安装包解压到了 /usr/local/nginx 目录,解决办法是将该目录重命名为其他名称后再执行 make,make install.

3、配置 nginx 开机启动

    切换到 /lib/systemd/system/ 目录,创建 nginx.service 文件 vim nginx.service

1
2
# cd /lib/systemd/system/
# vim nginx.service

文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=nginx 
After=network.target 
   
[Service] 
Type=forking 
ExecStart= /usr/local/nginx/sbin/nginx
ExecReload= /usr/local/nginx/sbin/nginx  reload
ExecStop= /usr/local/nginx/sbin/nginx  quit
PrivateTmp= true 
   
[Install] 
WantedBy=multi-user.target

    退出并保存文件,执行 systemctl enable nginx.service 使 nginx 开机启动

1
# systemctl enable nginx.service

systemctl start nginx.service    启动 nginx

systemctl stop nginx.service    结束 nginx

systemctl restart nginx.service    重启 nginx

4、验证是否安装成功

    输入 http:// 服务器 IP/ 如果能看到 nginx 的界面,就表示安装成功了

8326cffc1e178a8251695dc4f503738da977e879.jpg

 

(centos7) nginx 手动启动,关闭,开机自启

(centos7) nginx 手动启动,关闭,开机自启

个人博客:https://suveng.github.io/blog/​​​​​​​

Nginx 手动启动,关闭,开机自启

手动启动

  1. 去到 nginx 安装目录(解压目录)下,bin/nginx

    nginx -c nginx配置文件地址 
    

    例如

/usr/local/nginx/bin/nginx -c /usr/local/nginx/conf/nginx.conf

手动重启

nginx -s reload

手动关闭

  1. nginx -s stop
  2. nginx -s quit

开机自启

https://blog.csdn.net/king_kgh/article/details/79576813

查看状态

  1. ps -e | grep nginx

本文同步分享在 博客 "suveng"(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。

centOS 6.5 Nginx 配置开机启动

centOS 6.5 Nginx 配置开机启动

Nginx 是一个很强大的高性能Web和反向代理服务器。虽然使用命令行可以对Nginx进行各种操作,比如启动等,但是还是根据不太方便。下面介绍在Linux下安装后,如何设置开机自启动。

首先,在linux系统的/etc/init.d/目录下创建Nginx文件,使用如下命令:

vim/etc/init.d/Nginx

在脚本中添加如下命令:

#!/bin/sh
#
#Nginx-thisscriptstartsandstopstheNginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:Nginx
#config:/etc/Nginx/Nginx.conf
#config:/etc/sysconfig/Nginx
#pidfile:/var/run/Nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
Nginx="/usr/sbin/Nginx"
prog=$(basename$Nginx)
Nginx_CONF_FILE="/etc/Nginx/Nginx.conf"
[-f/etc/sysconfig/Nginx]&&./etc/sysconfig/Nginx
lockfile=/var/lock/subsys/Nginx
make_dirs(){
#makerequireddirectories
user=`$Nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`
if[-z"`grep$user/etc/passwd`"];then
useradd-M-s/bin/nologin$user
fi
options=`$Nginx-V2>&1|grep'configurearguments:'`
foroptin$options;do
if[`echo$opt|grep'.*-temp-path'`];then
value=`echo$opt|cut-d"="-f2`
if[!-d"$value"];then
#echo"creating"$value
mkdir-p$value&&chown-R$user$value
fi
fi
done
}
start(){
[-x$Nginx]||exit5
[-f$Nginx_CONF_FILE]||exit6
make_dirs
echo-n$"Starting$prog:"
daemon$Nginx-c$Nginx_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
}
restart(){
configtest||return$?
stop
sleep1
start
}
reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$Nginx-HUP
RETVAL=$?
echo
}
force_reload(){
restart
}
configtest(){
$Nginx-t-c$Nginx_CONF_FILE
}
rh_status(){
status$prog
}
rh_status_q(){
rh_status>/dev/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac

这个脚本其实也不是我写的,谁写的呢,Nginx官方写的,脚本地址:http://wiki.nginx.org/RedHatNginxInitScript,不过要注意,如果你是自定义编译安装的Nginx,需要根据您的安装路径修改下面这两项配置:

Nginx=”/usr/sbin/Nginx” 修改成Nginx执行程序的路径。

Nginx_CONF_FILE=”/etc/Nginx/Nginx.conf” 修改成配置文件的路径。

保存脚本文件后设置文件的执行权限

chmoda+x/etc/init.d/Nginx

然后,就可以通过该脚本对Nginx服务进行管理了:

/etc/init.d/Nginxstart
/etc/init.d/Nginxstop

使用chkconfig进行管理

上面的方法完成了用脚本管理Nginx服务的功能,但是还是不太方便,比如要设置Nginx开机启动等。这时可以使用chkconfig来设置。

先将Nginx服务加入chkconfig管理列表:

chkconfig--add/etc/init.d/Nginx

加完这个之后,就可以使用service对Nginx进行启动,重启等操作了。

serviceNginxstart
serviceNginxstop

设置终端模式开机启动:

chkconfigNginxon

chkconfig命令的使用方法,就不多数啦,可以自行搜索



另外这里还有一个网友分享的脚本(脚本地址:http://blog.163.com/qsc0624@126/blog/static/140324073201312734548701/):

#!/bin/bash
#NginxStartupscriptfortheNginxHTTPServer
#itisv.0.0.2version.
#chkconfig:-8515
#description:Nginxisahigh-performancewebandproxyserver.
#Ithasalotoffeatures,butit'snotforeveryone.
#processname:Nginx
#pidfile:/var/run/Nginx.pid
#config:/usr/local/Nginx/conf/Nginx.conf
Nginxd=/usr/local/Nginx/sbin/Nginx
Nginx_config=/usr/local/Nginx/conf/Nginx.conf
Nginx_pid=/var/run/Nginx.pid
RETVAL=0
prog="Nginx"
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
[${NETWORKING}="no"]&&exit0
[-x$Nginxd]||exit0
#StartNginxdaemonsfunctions.
start(){
if[-e$Nginx_pid];then
echo"Nginxalreadyrunning...."
exit1
fi
echo-n$"Starting$prog:"
daemon$Nginxd-c${Nginx_config}
RETVAL=$?
echo
[$RETVAL=0]&&touch/var/lock/subsys/Nginx
return$RETVAL
}
#StopNginxdaemonsfunctions.
stop(){
echo-n$"Stopping$prog:"
killproc$Nginxd
RETVAL=$?
echo
[$RETVAL=0]&&rm-f/var/lock/subsys/Nginx/var/run/Nginx.pid
}
#reloadNginxservicefunctions.
reload(){
echo-n$"Reloading$prog:"
#kill-HUP`cat${Nginx_pid}`
killproc$Nginxd-HUP
RETVAL=$?
echo
}
#Seehowwewerecalled.
case"$1"in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status$prog
RETVAL=$?
;;
*)
echo$"Usage:$prog{start|stop|restart|reload|status|help}"
exit1
esac
exit$RETVAL

使用此脚本的时候,也同样需要将配置路径修改成自己的

centos 67安装nginx 110 centos7 nginx php centos官网 centos下

centos 67安装nginx 110 centos7 nginx php centos官网 centos下

一、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
登录后复制

二、首先要安装 PCRE

PCRE 作用是让 Ngnix 支持 Rewrite 功能。

1,下载 PCRE 安装包
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包:
    [root@bogon src]# tar zxvf pcre-8.35.tar.gz
3、进入安装包目录
    [root@bogon src]# cd pcre-8.35
4、编译安装 
    [root@bogon pcre-8.35]# ./configure
    [root@bogon pcre-8.35]# make &amp;&amp; make install
5、查看pcre版本
    [root@bogon pcre-8.35]# pcre-config --version
登录后复制

三, 安装 Nginx1.10

导入yum config nginx

  • To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:
  • cd /etc/yum.repos.d
  • vi nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/6/$basearch/
    gpgcheck=0
    enabled=1
  • yum list nginx
  • yum install nginx-86-64-1.10

四,开放80端口

  • /sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT #开启8080端口
  • etc/rc.d/init.d/iptables save #保存配置
  • /etc/rc.d/init.d/iptables restart #重启防火墙

浏览器访问主机ip即可

立即学习“PHP免费学习笔记(深入)”;

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了centos 67安装nginx 110,包括了centos,nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

CentOS 7 设置Nginx开机启动

CentOS 7 设置Nginx开机启动

转自https://www.cnblogs.com/jepson6669/p/9131217.html

第一步:在/lib/systemd/system目录下创建nginx.service文件

第二步:编辑nginx.service文件:

[Unit]                                                      #服务说明

Description=nginx service                    #服务描述

After=network.target                            #服务类别描述

[Service]                                              #服务运行参数的设置

Type=forking                                       #以后台方式运行 

ExecStart=/usr/local/nginx/sbin/nginx         #启动命令,./usr/local/nginx/sbin/nginx 为nginx启动命令

ExecReload=/usr/local/nginx/sbin/nginx -s reload #重启命令,=后面为nginx重启命令

ExecStop=/usr/local/nginx/sbin/nginx -s quit        #退出命令,=后面为nginx退出命令

PrivateTmp=true                                                   #为服务分配独立的临时空间

[Install]                                                                  #运行级别下服务安装的相关设置

WantedBy=multi-user.target                                 #设置为多用户

第三步:加入开机启动

# systemctl enable nginx.service

取消开机自启动

#systemctl disable nginx.service

启动nginx服务

#systemctl start nginx.service

停止nginx服务

#systemctl stop nginx.service

重启nginx服务

#systemctl restart nginx.service

查看所有以启动的服务

#systemctl list-units --type=service

查看服务当前状态

#systemctl status nginx.service

遇到的错误

Warning: nginx.service changed on disk. Run ''systemctl daemon-reload'' to reload units.

按照提示执行命令systemctl daemon-reload即可。

 

今天关于centos7 安装与配置 nginx1.11,开机启动的讲解已经结束,谢谢您的阅读,如果想了解更多关于(centos7) nginx 手动启动,关闭,开机自启、centOS 6.5 Nginx 配置开机启动、centos 67安装nginx 110 centos7 nginx php centos官网 centos下、CentOS 7 设置Nginx开机启动的相关知识,请在本站搜索。

本文标签: