lanmp-nginx源码编译

Nginx源码编译安装

下载nginx

[root@server79 ~]# tar zxf nginx-1.4.2.tar.gz

[root@server79 core]# pwd

/root/nginx-1.4.2/src/core

[root@server79 core]# vim nginx.h

#define NGINX_VER          "linux"

注释掉gcc编译时的debug

[root@server79 nginx-1.4.2]# vim auto/cc/gcc  

# debug

#CFLAGS="$CFLAGS -g"

安装编译工具

yum install gcc make -y

开始编译,支持https,自带查看状态

[root@server79 nginx-1.4.2]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module

错误1

./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.

解决:

[root@server79 nginx-1.4.2]# yum install pcre-devel -y

[root@server79 nginx-1.4.2]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module

错误2

./configure: error: SSL modules require the OpenSSL library.

You can either do not enable the modules, 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.

解决:

[root@server79 nginx-1.4.2]# yum install openssl-devel -y

[root@server79 nginx-1.4.2]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module

[root@server79 nginx-1.4.2]# make && make install

[root@server79 conf]# vim /usr/local/lnmp/nginx/conf/nginx.conf

worker_processes  2;

events {

       use epoll;

   worker_connections  1024;

}

为了操作方便做一软链接,在任何目录都可以使用命令启动nginx

[root@server79 sbin]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/

检测nginx的配置,检测nginx语法

[root@server79 sbin]# nginx -t

nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful

启动nginx

[root@server79 sbin]# nginx

(关闭nginx用命令nginx -s stop)

[root@server79 html]# curl -I localhost

HTTP/1.1 200 OK

Server: linux

Date: Sun, 13 Apr 2014 09:29:27 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Sun, 13 Apr 2014 09:14:22 GMT

Connection: keep-alive

ETag: "534a556e-264"

Accept-Ranges: bytes

测试:

浏览器中:http://192.168.0.179

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.


你可能感兴趣的:(nginx源码编译)