分享基地

系统运维

nginx 在centos环境下安装

世纪黑猫 2015-03-21 系统运维 4,909


e12f36dc2d1f2c2e9da0bac21bf6cffa_1426870198_34.gif 

1、安装nginx并编译程序

安装编译工具,在此我使用了Yum进行配置

  #yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel -y
# yum install gcc gcc-c++ automake autoconf -y

为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Compatible Regular Expressions)包。您可以到 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包

#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz

#tar xf pcre-8.30.tar.gz 
# cd pcre-8.30
#./configure 
#make && make install

接着我将下载nginx,在此我下载了,

# wget http://nginx.org/download/nginx-1.1.9.tar.gz

#  tar xf nginx-1.1.9.tar.gz 
#  cd nginx-1.1.9
#  ./configure –with-http_stub_status_module –prefix=/usr/local/nginx

其中参数 –with-http_stub_status_module 是为了启用 nginx 的 NginxStatus 功能,用来监控 Nginx 的当前状态。 也可以通过./configure –help来查看 nginx可编译选项!

#  make
#  make install

编译安装完成后。因刚才编译的时候,选择的路径为/usr/loca/nginx。如果不设路径。默认也是此位置 。

安装完成后,进入目录 ,可以看到一些目录
#  cd /usr/local/nginx/

四个子目录分别是:conf、html、logs、sbin 。其中 Nginx 的配置文件存放于 conf/nginx.conf,Nginx 只有一个程序文件位于 sbin 目录下的 nginx 文件。

2、启动nginx
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

参数-c 指定配置文件路径,通过 打开浏览器,可以看到,欢迎画面。

nginx.sc

3、通过ps查看nginx进程是否正在运行。

[root@nginx nginx]# ps -ef |grep nginx

root     18854     1  0 13:24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   18855 18854  0 13:24 ?        00:00:00 nginx: worker process                                         
root     18902 12682  0 13:41 pts/2    00:00:00 grep nginx