源代码编译方式安装Nginx


:Mr.zhou  阅读: 1,219 次

  CentOS 6.6 中以源代码编译方式安装 Nginx 。nginx

  当前系统环境:

[root@nginx ~]# uname -r&&ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4}'
2.6.32-504.el6.x86_64
172.16.1.140
[root@nginx ~]#

  安装依赖 : pcre-devel openssl openssl-devel

[root@nginx src]# yum -q -y install pcre-devel openssl openssl-devel
[root@nginx src]# echo $?
0
[root@nginx src]# 

  从 Nginx 官网下载源码包,并解压:

[root@nginx ~]# cd /usr/local/src/
[root@nginx src]# wget -q http://nginx.org/download/nginx-1.8.0.tar.gz
[root@nginx src]# echo $?
0
[root@nginx src]# ls
nginx-1.8.0.tar.gz
[root@nginx src]# tar xf nginx-1.8.0.tar.gz 
[root@nginx src]# ls
nginx-1.8.0  nginx-1.8.0.tar.gz
[root@nginx src]# 

  创建 Nginx 工作时使用的用户和组 www。

[root@nginx src]# useradd -s /sbin/nologin -M www
[root@nginx src]# id www
uid=500(www) gid=500(www) groups=500(www)
[root@nginx src]# 

  指定编译选项:

[root@nginx src]# cd nginx-1.8.0
[root@nginx nginx-1.8.0]# ./configure \
> --prefix=/usr/local/nginx-1.8.0 \
> --user=www \
> --group=www \
> --with-http_ssl_module \
> --with-http_stub_status_module
checking for OS
 + Linux 2.6.32-504.el6.x86_64 x86_64
checking for C compiler ... found
...
[root@nginx nginx-1.8.0]# echo $?
0
[root@nginx nginx-1.8.0]# 

  编译 安装:

[root@nginx nginx-1.8.0]# make -s&&make -s install
[root@nginx nginx-1.8.0]# echo $?
0
[root@nginx nginx-1.8.0]# 

  建立软链接,加入环境变量。

[root@nginx nginx-1.8.0]# cd /usr/local/
[root@nginx local]# ls
bin  games    lib    libexec      sbin   src
etc  include  lib64  nginx-1.8.0  share
[root@nginx local]# ln -s /usr/local/nginx-1.8.0/ /usr/local/nginx
[root@nginx local]# ls
bin  games    lib    libexec  nginx-1.8.0  share
etc  include  lib64  nginx    sbin         src
[root@nginx local]#
[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ls
nginx
[root@nginx sbin]# pwd
/usr/local/nginx/sbin
[root@nginx sbin]# echo -e 'PATH=/usr/local/nginx/sbin:$PATH\nexport PATH'>>/etc/profile
[root@nginx sbin]# tail -2 /etc/profile
PATH=/usr/local/nginx/sbin:$PATH
export PATH
[root@nginx sbin]# 
[root@nginx sbin]# source /etc/profile

  启动 Nginx 测试:

[root@nginx sbin]# nginx
[root@nginx sbin]# curl -I 172.16.1.140
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Fri, 10 Jul 2015 22:58:26 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 10 Jul 2015 22:42:34 GMT
Connection: keep-alive
ETag: "55a04a5a-264"
Accept-Ranges: bytes

[root@nginx sbin]# 

  Nginx 安装成功。

  将 nginx 设置为开机自启动:

[root@nginx sbin]# which nginx
/usr/local/nginx/sbin/nginx
[root@nginx sbin]# echo '/usr/local/nginx/sbin/nginx'>>/etc/rc.local 
[root@nginx sbin]# tail -1 /etc/rc.local 
/usr/local/nginx/sbin/nginx
[root@nginx sbin]# 

转载请注明原文链接:http://www.z-dig.com/compile-the-source-code-install-nginx.html



正文部分到此结束