2018-01-13 11:47:25来源:cnblogs.com作者:zhj5551人点击

分享
  1 <!DOCTYPE html>  2 <html lang="zh-cn">  3 <head>  4 <meta charset="utf-8"/>  5 <meta name="viewport" content="width=device-width, initial-scale=1" />  6 <title>Linux(Centos)之安装Nginx及注意事项 - Kencery - 博客园</title>  7 <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=ON3Mxdo4-HlSMqbNDBZXhFIcGLon3eZDvU8zBESgwkk1"/>  8 <link id="MainCss" type="text/css" rel="stylesheet" href="/skins/CodingLife/bundle-CodingLife.css?v=g4Oce5UBaUn_FUwadcT09ICEg5NkULQGtUpNhTtrI8U1"/>  9 <link type="text/css" rel="stylesheet" href="/blog/customcss/104052.css?v=HD7ImyCowhezR3%2fYLj6EjKXXf0k%3d"/> 10 <link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="/skins/CodingLife/bundle-CodingLife-mobile.css?v=Xay8b9tTSw814nBzbOgvS6rrbcxrobMhvHJHdZAO9vI1"/> 11 <link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/hanyinglong/rss"/> 12 <link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/hanyinglong/rsd.xml"/> 13 <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/hanyinglong/wlwmanifest.xml"/> 14 <script src="//common.cnblogs.com/scripts/jquery-2.2.0.min.js"></script> 15 <script type="text/javascript">var currentBlogApp = 'hanyinglong', cb_enable_mathjax=false;var isLogined=true;</script> 16 <script src="/bundles/blog-common.js?v=O-NTEmnhjbG7lSYLc3yeqkrVxfMJyY9iXf4xyjlKikw1" type="text/javascript"></script> 17 </head> 18 <body> 19 <a name="top"></a> 20 <div id="page_begin_html"></div><script>load_page_begin_html();</script> 21  22 <!--done--> 23 <div id="home"> 24 <div id="header"> 25     <div id="blogTitle"> 26     <a id="lnkBlogLogo" href="http://www.cnblogs.com/hanyinglong/"><img id="blogLogo" src="/Skins/custom/images/logo.gif" alt="返回主页" /></a>             27          28 <!--done--> 29 <h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/hanyinglong/">怪才(Kencery)</a></h1> 30 <h2>菜鸟的里程中只有奋斗,别无其他</h2> 31  32  33  34          35     </div><!--end: blogTitle 博客的标题和副标题 --> 36     <div id="navigator"> 37          38 <ul id="navList"> 39 <li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">博客园</a></li> 40 <li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/hanyinglong/">首页</a></li> 41 <li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li> 42 <li><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/Kencery">联系</a></li> 43 <li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/hanyinglong/rss">订阅</a> 44 <!--<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/hanyinglong/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li> 45 <li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li> 46 </ul> 47         <div class="blogStats"> 48              49              50              51         </div><!--end: blogStats --> 52     </div><!--end: navigator 博客导航栏 --> 53 </div><!--end: header 头部 --> 54  55 <div id="main"> 56     <div id="mainContent"> 57     <div class="forFlow"> 58          59 <div id="post_detail"> 60 <!--done--> 61 <div id="topics"> 62     <div class = "post"> 63         <h1 class = "postTitle"> 64             <a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/hanyinglong/p/5102141.html">Linux(Centos)之安装Nginx及注意事项</a> 65         </h1> 66         <div class="clear"></div> 67         <div class="postBody"> 68             <div id="cnblogs_post_body" class="blogpost-body"><h1>1.Nginx的简单说明</h1> 69 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">  a. &nbsp;Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,期初开发的目的就是为了代理电子邮件服务器室友:Igor Sysoev开发,源代码符合BSD开源。其特点就是占用内存少并发能力强,在天朝使用Nginx的大型网站已经有很多:百度、淘宝、腾讯等等...。</span></span></p> 70 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">  b.Nginx作为Http服务器,有以下几项基本特征:</span></span></p> 71 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">    b.1 处理静态文件,索引文件以及自动索引,打开文件描述符缓冲。</span></span></p> 72 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">    b.2 无缓存的反向代理加速,简单的负载均衡和容错</span></span></p> 73 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">    b.3 模块化的结构,包括gzipping,byte ranges,chunked responses以及SSI-filter等filter,如果由FastCGI或其它代理服务器处理蛋液中存在的多个SSI,则这项处理可以并行运行,而不需要相互等待。</span></span></p> 74 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">    b.4 支持SSL和TLSSNI。</span></span></p> 75 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">  c.Nginx官网:http://nginx.org/</span></span></p> 76 <p><span style="font-size: 16px;"><span style="line-height: 1.5;">  d.Nginx推荐学习网址:http://dreamfire.blog.51cto.com/418026/1140965</span></span></p> 77 <h1>2.准备工作</h1> 78 <p><span style="font-size: 16px;">  a.上面简单介绍了一下Nginx,大家如果想要了解更多关于Nginx的知识,请自行通过网络学习。</span></p> 79 <p><span style="font-size: 16px;">  b.工欲善其事必先利其器,下面我们就在Linux下面简单安装一下Niginx,在安装过程中需要了一些问题,同步都会在博客中说出来。</span></p> 80 <p><span style="font-size: 16px;">  c.Nginx的安装依赖于以下三个包,意思就是在安装Nginx之前首先必须安装一下的三个包,安装顺序为我写的顺序:</span></p> 81 <p><span style="font-size: 16px;">    c.1 SSL功能需要openssl库,下载地址:<a href="http://www.openssl.org/"><span class="15">http://www.openssl.org/</span></a></span></p> 82 <p><span style="font-size: 16px;">    c.2 gzip模块需要zlib库,下载地址:<a href="http://www.zlib.net/"><span class="15">http://www.zlib.net/</span></a></span></p> 83 <p><span style="font-size: 16px;">    c.3 rewrite模块需要pcre库,下载地址:<a href="http://www.pcre.org/"><span class="15">http://www.pcre.org/</span></a></span></p> 84 <p><span style="font-size: 16px;">  d.Nginx的安装包:下载地址为:<a href="http://nginx.org/en/download.html"><span class="16">http://nginx.org/en/download.html</span></a></span></p> 85 <p><span style="font-size: 16px;"><span class="16">  e.将上面下载的几个软件全部使用Xftp上传到Linux系统中,上传路径和软件如图所示:</span></span></p> 86 <p><span style="font-size: 16px;"><span class="16">    <img src="https://images2015.cnblogs.com/blog/359161/201601/359161-20160118112457826-1166581674.png" alt="" /></span></span></p> 87 <p><span style="font-size: 16px;"><span class="16">  f.操作</span><span class="16">需要的软件以及系统如下:虚拟机(Vmware),虚拟</span><span class="16">机中安装的Centos系统,Xshell,Xftp,以及上面的几个包。</span></span></p> 88 <p><span style="font-size: 16px;">&nbsp;  g.下面开始按照上面说的按照顺序开始安装软件。</span></p> 89 <h1>3.安装SSL功能需要openssl库以及gzip模块需要的zlib库</h1> 90 <p><span style="font-size: 16px;">  a(1).首先我们安装SSL功能需要的openssl库插件,注意:安装过程是按照我在linux下设置的文件路径来安装的,命令如下:</span></p> 91 <p><span style="font-size: 16px;">    a.1 &nbsp; tar -zxvf &nbsp;soft/openssl-SNAP-20160104</span></p> 92 <p><span style="font-size: 16px;">    a.2 &nbsp; cd&nbsp;cd openssl-SNAP-20160104/</span></p> 93 <p><span style="font-size: 16px;">    a.3 &nbsp;&nbsp;./config</span></p> 94 <p><span style="font-size: 16px;">    a.4 &nbsp; make</span></p> 95 <p><span style="font-size: 16px;">    a.5 &nbsp; make install</span></p> 96 <p><span style="font-size: 16px;">  b(1).安装gzip模块需要zlib库的安装方法和openssl安装的方法一模一样,也是分为上面五个步骤,只不过是文件的名称不一样,命令简单如下:</span></p> 97 <p><span style="font-size: 16px;">    b.1 &nbsp; tar -zxvf &nbsp;soft/openssl-SNAP-20160104</span></p> 98 <p><span style="font-size: 16px;">    b.2 &nbsp; cd openssl-SNAP-20160104/</span></p> 99 <p><span style="font-size: 16px;">    b.3 &nbsp;&nbsp;./configure&nbsp;</span></p>100 <p><span style="font-size: 16px;">    b.4 &nbsp; make</span></p>101 <p><span style="font-size: 16px;">    b.5 &nbsp; make install</span></p>102 <p><span style="font-size: 16px;">  b.如果没有报错,则说明安装完全完成了~。</span></p>103 <h1>4.安装&nbsp;rewrite模块需要pcre库</h1>104 <p>  <span style="font-size: 16px;">a.安装&nbsp;rewrite模块需要pcre库的安装方法和openssl安装的方法一模一样,也是分为上面五个步骤,只不过是文件的名称不一样,命令简单如下:</span></p>105 <p><span style="font-size: 16px;">    a.1 &nbsp;&nbsp;tar -zxvf soft/pcre-8.38.tar.gz</span></p>106 <p><span style="font-size: 16px;">    a.2 &nbsp;&nbsp;cd pcre-8.38/</span></p>107 <p><span style="font-size: 16px;">    a.3 &nbsp;&nbsp;./configure&nbsp;</span></p>108 <p><span style="font-size: 16px;">    a.4 &nbsp; make</span></p>109 <p><span style="font-size: 16px;">    a.5 &nbsp; make install</span></p>110 <p><span style="font-size: 16px;">  b.在执行./configure的出现错误了,导致不能继续往下执行,报错内容为:</span></p>111 <p><span style="font-size: 16px;">    error: You need a C++ compiler for C++ support,看到这句话我们就已经猜到了应该是c++包信息,而linux中没有,那么首先安装一下这个包信息即可,安装命令为:</span></p>112 <p><span style="font-size: 16px;">    b.1 &nbsp;</span>yum install -y gcc gcc-c++</p>113 <p><span style="font-size: 16px;">  c.当安装完上面的c++包之后,在此运行,发现消息已经显示安装成功了,当基于上面的东西全部安装完成之后,就需要安装Nginx服务了。</span></p>114 <h1>5.安装 Nginx服务</h1>115 <p><span style="font-size: 16px;">  a.安装&nbsp;rewrite模块需要pcre库的安装方法和openssl安装的方法一模一样,也是分为上面五个步骤,只不过是文件的名称不一样,命令简单如下:</span></p>116 <p><span style="font-size: 16px;">    a.1 &nbsp;&nbsp;tar -zxvf soft/nginx-1.9.9.tar.gz</span></p>117 <p><span style="font-size: 16px;">    a.2 &nbsp;&nbsp;cd nginx-1.9.9/</span></p>118 <p><span style="font-size: 16px;">    a.3 &nbsp; ./configure --with-pcre=../pcre-8.38/ --with-zlib=../zlib-1.2.8/ --with-openssl=../openssl-SNAP-20160104/</span></p>119 <p><span style="font-size: 16px;">    a.4 &nbsp; make</span></p>120 <p><span style="font-size: 16px;">    a.5 &nbsp; make install</span></p>121 <p><span style="font-size: 16px;">  b.在执行./configure的出现错误了,导致不能继续往下执行,报错内容为:</span></p>122 <p><span style="font-size: 16px;">    error: You need a C++ compiler for C++ support,看到这句话我们就已经猜到了应该是c++包信息,而linux中没有,那么首先安装一下这个包信息即可,安装命令为:</span></p>123 <p><span style="font-size: 16px;">    b.1 &nbsp;yum install -y gcc gcc-c++</span></p>124 <p><span style="font-size: 16px;">  c.当安装完上面的c++包之后,在此运行,发现消息已经显示安装成功了。博文到这里如果安装的时候没有遇到错误的话说明已经安装成功了,下面我们就是测试Nginx是否安装成功。</span></p>125 <h1>6.监测Nginx是否安装成功</h1>126 <p><span style="font-size: 16px;">  a.当上面的所有步骤完成之后,则说明Nginx安装已经完成,那么我们如何来确定是否安装成功了呢?通过以下命令来确定即可。</span></p>127 <p><span style="font-size: 16px;">    a.1 &nbsp;cd /usr/local/nginx/sbin/</span></p>128 <p><span style="font-size: 16px;">    a.2 ./nginx -t</span></p>129 <p><span style="font-size: 16px;">  b. 当我执行第二个命令(./nginx -t)的时候出错了,报没有权限的错误。如图所示:</span></p>130 <p><span style="font-size: 16px;">    <img src="https://images2015.cnblogs.com/blog/359161/201601/359161-20160118142931982-1128468684.png" alt="" width="895" height="102" /></span></p>131 <p> <span style="font-size: 16px;">   备注:根据错误提示,我们就能够看出来,是说/usr/local/nginx下没有权限,解决办法也很简单,我们给文件赋值权限。</span></p>132 <p><span style="font-size: 16px;">  c.如下图所示,配置权限(配置权限需要切换到root用户下)之后,执行上面两个步骤,如果linux中如下图所示:则说明安装已成功。</span></p>133 <p><span style="font-size: 16px;">    <img src="https://images2015.cnblogs.com/blog/359161/201601/359161-20160118143413826-294114267.png" alt="" /></span></p>134 <p><span style="font-size: 16px;">  d.当确认安装完成之后,首先就需要启动和查看Nginx默认安装的端口是多少,两个命令分别如下:</span></p>135 <p><span style="font-size: 16px;">    (1) &nbsp;</span><span style="font-size: 16px; line-height: 26.6666679382324px;">./nginx</span></p>136 <p><span style="font-size: 16px; line-height: 26.6666679382324px;">    (2) &nbsp;</span><span style="font-size: 16px; line-height: 26.6666679382324px;">netstat -ntlp &nbsp;, &nbsp;Nginx默认端口为80</span></p>137 <p><span style="font-size: 16px;">  e.开放80端口,让其外部环境可以访问(如果不开放80端口,外部环境访问不了),命令以及截图如下:<br /></span></p>138 <p><span style="font-size: 16px;">    vim /etc/sysconfig/iptables</span></p>139 <p><span style="font-size: 16px;">    <span style="color: #ff0000;">备注:</span>这里我使用vim更改防火强信息之后,在重新启动防火墙的时候出现了错误,错误信息为:Try `iptables-restore -h' or 'iptables-restore --help' for more information,这个错误信息提示我们不能重新启动防火墙,那怎么办呢?测试了一下已写命令的方式去更改,发现更改成功了,如图所示:</span></p>140 <p><span style="font-size: 16px;">      <img src="https://images2015.cnblogs.com/blog/359161/201601/359161-20160118145813373-1261463342.png" alt="" /></span></p>141 <p><span style="font-size: 16px;">  f.当上面的工作完成之后,我们在外部浏览器中浏览:http://IP,出现如图所示,则说明安装已完全完成。</span></p>142 <p><span style="font-size: 16px;">    <img src="https://images2015.cnblogs.com/blog/359161/201601/359161-20160118150017513-1715983539.png" alt="" /></span></p>143 <p>&nbsp;</p>144 <h1>7.将Nginx设置为开机自动启动</h1>145 <p>&nbsp;</p>146 <p><span style="font-size: 16px;">  a.当上面6步完成之后,说明安装已经完全成功了,但是每次开机我们面临的一个问题,就是每次都要执行命令(1: cd /usr/local/nginx/sbin/ &nbsp; 2:./nginx -t),那么这时候有这个需要,设置开机自启动,开机自动启动的命令为:将Nginx的启动命令添加到/etc/rc.local,命令如下:</span></p>147 <p><span style="line-height: 1.5; font-size: 16px;">    echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" &gt;&gt; /etc/rc.local</span></p>148 <p><span style="font-size: 16px;">  b.然后将Linux关机重启测试一下,如果http://IP还能够访问,则说明配置成功了,我这边已测试,配置完全成功。</span></p>149 <p>&nbsp;</p>150 <h1>8.使用server命令启动nginx服务</h1>151 <p>&nbsp;<span style="font-size: 16px;">  a. &nbsp;现在觉得启动命令太麻烦,虽然开机可以自启动,但是每次改动要重新启动nginx的话,要么输入命令,要么开机,都还不是很好,那么我们能不能创造一个更好的方式呢?当然可以,我们可以通过设置System V脚本。</span></p>152 <p><span style="font-size: 16px;">  b.脚本代码如下所示:</span></p>153 <div class="cnblogs_code" onclick="cnblogs_code_show('d439d86f-d1f3-4075-9434-ec62ef29726f')"><img id="code_img_closed_d439d86f-d1f3-4075-9434-ec62ef29726f" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt="" /><img id="code_img_opened_d439d86f-d1f3-4075-9434-ec62ef29726f" class="code_img_opened" style="display: none;" onclick="cnblogs_code_hide('d439d86f-d1f3-4075-9434-ec62ef29726f',event)" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="" />154 <div id="cnblogs_code_open_d439d86f-d1f3-4075-9434-ec62ef29726f" class="cnblogs_code_hide">155 <pre><span style="color: #008080;">  1</span> #!/bin/<span style="color: #000000;">sh 156 </span><span style="color: #008080;">  2</span> <span style="color: #000000;"># 157 </span><span style="color: #008080;">  3</span> # nginx - this script starts <span style="color: #0000ff;">and</span><span style="color: #000000;"> stops the nginx daemon 158 </span><span style="color: #008080;">  4</span> <span style="color: #000000;"># 159 </span><span style="color: #008080;">  5</span> # chkconfig: - <span style="color: #800080;">85</span> <span style="color: #800080;">15</span> 160 <span style="color: #008080;">  6</span> # description: Nginx <span style="color: #0000ff;">is</span> an HTTP(S) server, HTTP(S) reverse / 161 <span style="color: #008080;">  7</span> #   proxy <span style="color: #0000ff;">and</span> IMAP/<span style="color: #000000;">POP3 proxy server 162 </span><span style="color: #008080;">  8</span> <span style="color: #000000;"># processname: nginx 163 </span><span style="color: #008080;">  9</span> # config: /etc/nginx/<span style="color: #000000;">nginx.conf 164 </span><span style="color: #008080;"> 10</span> # config: /etc/sysconfig/<span style="color: #000000;">nginx 165 </span><span style="color: #008080;"> 11</span> # pidfile: /var/run/<span style="color: #000000;">nginx.pid 166 </span><span style="color: #008080;"> 12</span> # Source <span style="color: #0000ff;">function</span><span style="color: #000000;"> library. 167 </span><span style="color: #008080;"> 13</span> . /etc/rc.d/init.d/<span style="color: #000000;">functions 168 </span><span style="color: #008080;"> 14</span> <span style="color: #000000;"># Source networking configuration. 169 </span><span style="color: #008080;"> 15</span> . /etc/sysconfig/<span style="color: #000000;">network 170 </span><span style="color: #008080;"> 16</span> # Check that networking <span style="color: #0000ff;">is</span><span style="color: #000000;"> up. 171 </span><span style="color: #008080;"> 17</span> [ <span style="color: #808080;">"</span><span style="color: #808080;">$NETWORKING" = "no" ] &amp;&amp; exit 0 </span>172 <span style="color: #008080;"> 18</span>     nginx=<span style="color: #808080;">"</span><span style="color: #808080;">/usr/local/nginx/sbin/nginx" </span>173 <span style="color: #008080;"> 19</span>     prog=<span style="color: #000000;">$(basename $nginx) 174 </span><span style="color: #008080;"> 20</span>     NGINX_CONF_FILE=<span style="color: #808080;">"</span><span style="color: #808080;">/usr/local/nginx/conf/nginx.conf" </span>175 <span style="color: #008080;"> 21</span> [ -f /etc/sysconfig/nginx ] &amp;&amp; . /etc/sysconfig/<span style="color: #000000;">nginx 176 </span><span style="color: #008080;"> 22</span>     lockfile=/var/lock/subsys/<span style="color: #000000;">nginx 177 </span><span style="color: #008080;"> 23</span>  178 <span style="color: #008080;"> 24</span> <span style="color: #000000;">start() { 179 </span><span style="color: #008080;"> 25</span>     [ -x $nginx ] || <span style="color: #0000ff;">exit</span> <span style="color: #800080;">5</span> 180 <span style="color: #008080;"> 26</span>     [ -f $NGINX_CONF_FILE ] || <span style="color: #0000ff;">exit</span> <span style="color: #800080;">6</span> 181 <span style="color: #008080;"> 27</span>     echo -n $<span style="color: #808080;">"</span><span style="color: #808080;">Starting $prog: " </span>182 <span style="color: #008080;"> 28</span>     daemon $nginx -<span style="color: #000000;">c $NGINX_CONF_FILE 183 </span><span style="color: #008080;"> 29</span>     retval=<span style="color: #000000;">$? 184 </span><span style="color: #008080;"> 30</span> <span style="color: #000000;">    echo 185 </span><span style="color: #008080;"> 31</span> [ $retval -eq <span style="color: #800080;">0</span> ] &amp;&amp;<span style="color: #000000;"> touch $lockfile 186 </span><span style="color: #008080;"> 32</span> <span style="color: #000000;">    return $retval 187 </span><span style="color: #008080;"> 33</span> <span style="color: #000000;">} 188 </span><span style="color: #008080;"> 34</span>  189 <span style="color: #008080;"> 35</span> <span style="color: #000000;">stop() { 190 </span><span style="color: #008080;"> 36</span>     echo -n $<span style="color: #808080;">"</span><span style="color: #808080;">Stopping $prog: " </span>191 <span style="color: #008080;"> 37</span>     killproc $prog -<span style="color: #000000;">QUIT 192 </span><span style="color: #008080;"> 38</span>     retval=<span style="color: #000000;">$? 193 </span><span style="color: #008080;"> 39</span> <span style="color: #000000;">    echo 194 </span><span style="color: #008080;"> 40</span> [ $retval -eq <span style="color: #800080;">0</span> ] &amp;&amp; rm -<span style="color: #000000;">f $lockfile 195 </span><span style="color: #008080;"> 41</span> <span style="color: #000000;">    return $retval 196 </span><span style="color: #008080;"> 42</span>     killall -<span style="color: #800080;">9</span><span style="color: #000000;"> nginx 197 </span><span style="color: #008080;"> 43</span> <span style="color: #000000;">} 198 </span><span style="color: #008080;"> 44</span>  199 <span style="color: #008080;"> 45</span> <span style="color: #000000;">restart() { 200 </span><span style="color: #008080;"> 46</span> <span style="color: #000000;">    configtest || return $? 201 </span><span style="color: #008080;"> 47</span> <span style="color: #000000;">    stop 202 </span><span style="color: #008080;"> 48</span>     sleep <span style="color: #800080;">1</span> 203 <span style="color: #008080;"> 49</span> <span style="color: #000000;">    start 204 </span><span style="color: #008080;"> 50</span> <span style="color: #000000;">} 205 </span><span style="color: #008080;"> 51</span>  206 <span style="color: #008080;"> 52</span> <span style="color: #000000;">reload() { 207 </span><span style="color: #008080;"> 53</span> <span style="color: #000000;">    configtest || return $? 208 </span><span style="color: #008080;"> 54</span>     echo -n $<span style="color: #808080;">"</span><span style="color: #808080;">Reloading $prog: " </span>209 <span style="color: #008080;"> 55</span>     killproc $nginx -<span style="color: #000000;">HUP 210 </span><span style="color: #008080;"> 56</span>     RETVAL=<span style="color: #000000;">$? 211 </span><span style="color: #008080;"> 57</span> <span style="color: #000000;">    echo 212 </span><span style="color: #008080;"> 58</span> <span style="color: #000000;">} 213 </span><span style="color: #008080;"> 59</span>  214 <span style="color: #008080;"> 60</span> <span style="color: #000000;">force_reload() { 215 </span><span style="color: #008080;"> 61</span> <span style="color: #000000;">    restart 216 </span><span style="color: #008080;"> 62</span> <span style="color: #000000;">} 217 </span><span style="color: #008080;"> 63</span>  218 <span style="color: #008080;"> 64</span> <span style="color: #000000;">configtest() { 219 </span><span style="color: #008080;"> 65</span>     $nginx -t -<span style="color: #000000;">c $NGINX_CONF_FILE 220 </span><span style="color: #008080;"> 66</span> <span style="color: #000000;">} 221 </span><span style="color: #008080;"> 67</span>  222 <span style="color: #008080;"> 68</span> <span style="color: #000000;">rh_status() { 223 </span><span style="color: #008080;"> 69</span> <span style="color: #000000;">    status $prog 224 </span><span style="color: #008080;"> 70</span> <span style="color: #000000;">} 225 </span><span style="color: #008080;"> 71</span>  226 <span style="color: #008080;"> 72</span> <span style="color: #000000;">rh_status_q() { 227 </span><span style="color: #008080;"> 73</span>     rh_status &gt;/dev/null <span style="color: #800080;">2</span>&gt;&amp;<span style="color: #800080;">1</span> 228 <span style="color: #008080;"> 74</span> <span style="color: #000000;">} 229 </span><span style="color: #008080;"> 75</span>  230 <span style="color: #008080;"> 76</span> case <span style="color: #808080;">"</span><span style="color: #808080;">$1" in </span>231 <span style="color: #008080;"> 77</span> <span style="color: #000000;">    start) 232 </span><span style="color: #008080;"> 78</span>         rh_status_q &amp;&amp; <span style="color: #0000ff;">exit</span> <span style="color: #800080;">0</span> 233 <span style="color: #008080;"> 79</span>         $<span style="color: #800080;">1</span> 234 <span style="color: #008080;"> 80</span> <span style="color: #000000;">    ;; 235 </span><span style="color: #008080;"> 81</span> <span style="color: #000000;">    stop) 236 </span><span style="color: #008080;"> 82</span>         rh_status_q || <span style="color: #0000ff;">exit</span> <span style="color: #800080;">0</span> 237 <span style="color: #008080;"> 83</span>         $<span style="color: #800080;">1</span> 238 <span style="color: #008080;"> 84</span> <span style="color: #000000;">    ;; 239 </span><span style="color: #008080;"> 85</span> <span style="color: #000000;">    restart|configtest) 240 </span><span style="color: #008080;"> 86</span>         $<span style="color: #800080;">1</span> 241 <span style="color: #008080;"> 87</span> <span style="color: #000000;">    ;; 242 </span><span style="color: #008080;"> 88</span> <span style="color: #000000;">    reload) 243 </span><span style="color: #008080;"> 89</span>         rh_status_q || <span style="color: #0000ff;">exit</span> <span style="color: #800080;">7</span> 244 <span style="color: #008080;"> 90</span>         $<span style="color: #800080;">1</span> 245 <span style="color: #008080;"> 91</span> <span style="color: #000000;">    ;; 246 </span><span style="color: #008080;"> 92</span>     force-<span style="color: #000000;">reload) 247 </span><span style="color: #008080;"> 93</span> <span style="color: #000000;">        force_reload 248 </span><span style="color: #008080;"> 94</span> <span style="color: #000000;">    ;; 249 </span><span style="color: #008080;"> 95</span> <span style="color: #000000;">    status) 250 </span><span style="color: #008080;"> 96</span> <span style="color: #000000;">        rh_status 251 </span><span style="color: #008080;"> 97</span> <span style="color: #000000;">    ;; 252 </span><span style="color: #008080;"> 98</span>     condrestart|try-<span style="color: #000000;">restart) 253 </span><span style="color: #008080;"> 99</span>         rh_status_q || <span style="color: #0000ff;">exit</span> <span style="color: #800080;">0</span> 254 <span style="color: #008080;">100</span> <span style="color: #000000;">    ;; 255 </span><span style="color: #008080;">101</span>     *<span style="color: #000000;">) 256 </span><span style="color: #008080;">102</span>         echo $<span style="color: #808080;">"</span><span style="color: #808080;">Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" </span>257 <span style="color: #008080;">103</span>         <span style="color: #0000ff;">exit</span> <span style="color: #800080;">2</span> 258 <span style="color: #008080;">104</span> esac </pre>259 </div>260 <span class="cnblogs_code_collapse">server命令的代码</span></div>261 <p><span style="font-size: 16px;">  c.创建命令如下,手先跳转到/etc/init.d下创建nginx启动脚本文件,命令如下;</span></p>262 <p><span style="font-size: 16px;">    c.1&nbsp;cd /etc/init.d/</span></p>263 <p><span style="font-size: 16px;">    c.2&nbsp;vim nginx &nbsp;创建一个新的nginx文件,将上面的命令代码copy到里面,然后保存</span></p>264 <p><span style="font-size: 16px;">  d.修改脚本权限,命令如下:</span>chmod 755 nginx</p>265 <p>  e.将脚本文件加入到chkconfig中&nbsp;<span style="font-size: 16px; line-height: 26.6666679382324px;">&nbsp;chkconfig --add nginx</span></p>266 <p>&nbsp;</p>267 <p><span style="font-size: 16px;">  f.设置nginx开机在3和5级别自动启动 &nbsp;chkconfig --level 35 nginx on</span></p>268 <p><span style="font-size: 16px;">  g.测试nginx脚本文件是否能够正常使用,命令如下,我均已测试,全部可以使用。</span></p>269 <p><span style="font-size: 16px;">    g.1 &nbsp;/etc/init.d/nginx restart</span></p>270 <p><span style="font-size: 16px;">    g.2 &nbsp;/etc/init.d/nginx reload</span></p>271 <p><span style="font-size: 16px;">    g.3 &nbsp;&nbsp;/etc/init.d/nginx&nbsp;stop&nbsp;</span></p>272 <p><span style="font-size: 16px;">&nbsp;    </span></p>273 <p><span style="font-size: 16px;">    到这里我们这片笔记就完成了,能帮助大家就帮到,帮不到大家,谢谢大家了,这只是学习笔记,不用较真某些东西,谢谢~~~~</span></p>274 <p><span style="font-size: 16px;">      后面有机会我还会再说这块的,如何将一个网站部署到nginx下去~~~~</span></p>275 <p>         <span style="font-size: 18pt; color: #ff0000;">   每天的努力都是为了未来更够更好~~~~~</span></p></div><div id="MySignature"></div>276 <div class="clear"></div>277 <div id="blog_post_info_block">278 <div id="BlogPostCategory"></div>279 <div id="EntryTag"></div>280 <div id="blog_post_info">281 </div>282 <div class="clear"></div>283 <div id="post_next_prev"></div>284 </div>285 286 287         </div>288         <div class = "postDesc">posted @ <span id="post-date">2016-01-18 15:02</span> <a href='http://www.cnblogs.com/hanyinglong/'>Kencery</a> 阅读(<span id="post_view_count">...</span>) 评论(<span id="post_comment_count">...</span>)  <a href ="https://i.cnblogs.com/EditPosts.aspx?postid=5102141" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(5102141);return false;">收藏</a></div>289     </div>290     <script type="text/javascript">var allowComments=true,cb_blogId=104052,cb_entryId=5102141,cb_blogApp=currentBlogApp,cb_blogUserGuid='1ce54887-f521-e111-b422-842b2b196315',cb_entryCreatedDate='2016/1/18 15:02:00';loadViewCount(cb_entryId);var cb_postType=1;</script>291     292 </div><!--end: topics 文章、评论容器-->293 </div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>294 <div id='comment_form' class='commentform'>295 <a name='commentform'></a>296 <div id='divCommentShow'></div>297 <div id='comment_nav'><span id='span_refresh_tips'></span><a href='javascript:void(0);' onclick='return RefreshCommentList();' id='lnk_RefreshComments' runat='server' clientidmode='Static'>刷新评论</a><a href='#' onclick='return RefreshPage();'>刷新页面</a><a href='#top'>返回顶部</a></div>298 <div id='comment_form_container'></div>299 <div class='ad_text_commentbox' id='ad_text_under_commentbox'></div>300 <div id='ad_t2'></div>301 <div id='opt_under_post'></div>302 <div id='cnblogs_c1' class='c_ad_block'></div>303 <div id='under_post_news'></div>304 <div id='cnblogs_c2' class='c_ad_block'></div>305 <div id='under_post_kb'></div>306 <div id='HistoryToday' class='c_ad_block'></div>307 <script type='text/javascript'>308     fixPostBody();309     setTimeout(function () { incrementViewCount(cb_entryId); }, 50);310     deliverAdT2();311     deliverAdC1();312     deliverAdC2();    313     loadNewsAndKb();314     loadBlogSignature();315     LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);316     GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);317     loadOptUnderPost();318     GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);   319 </script>320 </div>321 322 323     </div><!--end: forFlow -->324     </div><!--end: mainContent 主体内容容器-->325 326     <div id="sideBar">327         <div id="sideBarMain">328             329 <!--done-->330 <div class="newsItem">331 <h3 class="catListTitle">公告</h3>332     <div id="blog-news"></div><script type="text/javascript">loadBlogNews();</script>333 </div>334 335             <div id="blog-calendar" style="display:none"></div><script type="text/javascript">loadBlogDefaultCalendar();</script>336             337             <div id="leftcontentcontainer">338                 <div id="blog-sidecolumn"></div><script type="text/javascript">loadBlogSideColumn();</script>339             </div>340             341         </div><!--end: sideBarMain -->342     </div><!--end: sideBar 侧边栏容器 -->343     <div class="clear"></div>344     </div><!--end: main -->345     <div class="clear"></div>346     <div id="footer">347         348 <!--done-->349 Copyright &copy;2018 Kencery350     </div><!--end: footer -->351 </div><!--end: home 自定义的最大容器 -->352 <!--PageEndHtml Block Begin-->353 友情链接:<a class="menu" target="_black" href="http://www.chuxinm.com">初心商城</a>354 355 <script type="text/javascript" language="javascript">356 357 //生成目录索引列表358 function GenerateContentList()359 {360     var jquery_h3_list = $('#cnblogs_post_body h1');//如果你的章节标题不是h3,只需要将这里的h3换掉即可361     if(jquery_h3_list.length>0)362     {363         var content = '<a name="_labelTop"></a>';364         content    += '<div id="navCategory">';365         content    += '<p><b>阅读目录</b></p>';366         content    += '<ul>';367         for(var i =0;i<jquery_h3_list.length;i++)368         {369             var go_to_top = '<div><a href="#_labelTop">回到顶部</a><a name="_label' + i + '"></a></div>';370             $(jquery_h3_list[i]).before(go_to_top);371             var li_content = '<li><a href="#_label' + i + '">' + $(jquery_h3_list[i]).text() + '</a></li>';372             content += li_content;373         }374         content    += '</ul>';375         content    += '</div>';376         if($('#cnblogs_post_body').length != 0 )377         {378             $($('#cnblogs_post_body')[0]).prepend(content);379         }380     }    381 }382 GenerateContentList();383 //为右下角推荐推荐区域添加关注按钮384 window.onload = function () {385     $('#div_digg').prepend('<div><span class="icon_favorite"></span><a onclick="cnblogs.UserManager.FollowBlogger(/'1ce54887-f521-e111-b422-842b2b196315/');" href="javascript:void(0);">关注一下楼主吧</a> </div>');386 }387 </script>388 <!--PageEndHtml Block End-->389 </body>390 </html>

相关文章

    无相关信息

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台