天天看点

CentOS6.5编译安装Nginx和Openssl

Nginx的编译安装:

1.下载Openssl

1

<code>[root@Node1 ~]</code><code># wget http://www.openssl.org/source/openssl-1.0.2.tar.gz</code>

2.下载nginx

<code>[root@Node1 ~]</code><code># wget http://nginx.org/download/nginx-1.6.2.tar.gz</code>

3.解压软件

2

<code>[root@Node1 ~]</code><code># tar zxf openssl-1.0.2.tar.gz</code>

<code>[root@Node1 ~]</code><code># tar zxf nginx-1.6.2.tar.gz</code>

4.编译Nginx

<code>[root@Node1 ~]</code><code># cd nginx-1.6.2</code>

<code>[root@Node1 nginx-1.6.2]</code><code># ./configure  --user=www --group=www --prefix=/data/nginx1.6.2 --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-openssl=/root/openssl-1.0.2</code>

注意:编译nginx添加ssl支持,如果需要编译的openssl,是不需要编译opensll,--with-openssl=DIR DIR是openssl的源码路径,不是openssl的安装路径,否则make时将出错:

3

4

5

6

7

8

9

10

11

12

<code>make</code><code>[1]: Entering directory `</code><code>/root/nginx-1</code><code>.6.2'</code>

<code>cd</code> <code>/server/openssl</code> <code>\</code>

<code>        </code><code>&amp;&amp; </code><code>make</code> <code>clean \</code>

<code>        </code><code>&amp;&amp; .</code><code>/config</code> <code>--prefix=</code><code>/server/openssl/openssl</code> <code>no-shared  no-threads \</code>

<code>        </code><code>&amp;&amp; </code><code>make</code> <code>\</code>

<code>        </code><code>&amp;&amp; </code><code>make</code> <code>install</code>

<code>make</code><code>[2]: Entering directory `</code><code>/server/openssl</code><code>'</code>

<code>make</code><code>[2]: *** No rule to </code><code>make</code> <code>target `clean'.  Stop.</code>

<code>make</code><code>[2]: Leaving directory `</code><code>/server/openssl</code><code>'</code>

<code>make</code><code>[1]: *** [</code><code>/server/openssl/openssl/include/openssl/ssl</code><code>.h] Error 2</code>

<code>make</code><code>[1]: Leaving directory `</code><code>/root/nginx-0</code><code>.7.61'</code>

<code>make</code><code>: *** [build] Error 2</code>

如果出现

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

<code>You can either disable the module by using --without-http_rewrite_module</code>

<code>option, or </code><code>install</code> <code>the PCRE library into the system, or build the PCRE library</code>

<code>statically from the </code><code>source</code> <code>with nginx by using --with-pcre=&lt;path&gt; option.</code>

这说明没有安装pcre &amp;  pcre-devel包,这里yum安装

<code>[root@Node1 nginx-1.6.2]</code><code># yum -y install pcre pcre-devel</code>

5.安装Nginx

<code>[root@Node1 nginx-1.6.2]</code><code># make</code>

<code>[root@Node1 nginx-1.6.2]</code><code># make install</code>

6.启动之前检查nginx

<code>[root@Node1 nginx-1.6.2]</code><code># /data/nginx1.6.2/sbin/nginx -t</code>

<code>nginx: the configuration </code><code>file</code> <code>/data/nginx1</code><code>.6.2</code><code>/conf/nginx</code><code>.conf syntax is ok</code>

<code>nginx: [emerg] getpwnam(</code><code>"www"</code><code>) failed</code>

<code>nginx: configuration </code><code>file</code> <code>/data/nginx1</code><code>.6.2</code><code>/conf/nginx</code><code>.conf </code><code>test</code> <code>failed</code>

检查发现是没有运行用户,新增www账户

<code>[root@Node1 nginx-1.6.2]</code><code># groupadd www</code>

<code>[root@Node1 nginx-1.6.2]</code><code># useradd -g www -s /sbin/nologin -d /dev/null www</code>

7.再次检查

[root@Node1 nginx-1.6.2]# /data/nginx1.6.2/sbin/nginx -t

nginx: the configuration file /data/nginx1.6.2/conf/nginx.conf syntax is ok

nginx: configuration file /data/nginx1.6.2/conf/nginx.conf test is successful

8.启动Nginx

<code>[root@Node1 nginx-1.6.2]</code><code># /data/nginx1.6.2/sbin/nginx</code>

9.检查端口

<code>[root@Node1 nginx-1.6.2]</code><code># netstat -ntlup |grep :80</code>

<code>tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      19849</code><code>/nginx</code>

10.检查进程

<code>[root@Node1 nginx-1.6.2]</code><code># ps aux |grep nginx</code>

<code>root     19849  0.0  0.0  22664   852 ?        Ss   11:19   0:00 nginx: master process </code><code>/data/nginx1</code><code>.6.2</code><code>/sbin/nginx</code>

<code>www      19850  0.0  0.1  23100  1448 ?        S    11:19   0:00 nginx: worker process</code>

<code>root     19858  0.0  0.0 103244   856 pts</code><code>/0</code>    <code>S+   11:21   0:00 </code><code>grep</code> <code>nginx</code>

11.网站访问

<a href="http://s3.51cto.com/wyfs02/M01/5A/16/wKioL1T2fL_zYxrrAAGEdK_4bkY849.jpg" target="_blank"></a>

本文转自 rong341233 51CTO博客,原文链接:http://blog.51cto.com/fengwan/1617167

继续阅读