编译安装nginx(如果将来需要批量部署安装nginx,可以自己做成rpm包。官方也有提供rpm包)
1、安装前准备
1)yum grouplist(查看安装了哪些yum包组)
2)yum -y groupinstall “Development Tools” (安装包组)
3)yum install -y pcre-devel openssl-devel gd(安装依赖,pcre是perl扩展的正则表达式)
2、解压缩
1)tar xf nginx-1.4.1.tar.gz(安装软件之前需要确认下时间,如果系统时间比软件包时间靠前的话,会认为软件包是来自未来的,因此软件包是无法使用的)
2)groupadd -r -g 108 nginx
3)useradd -r -g 108 -u 108 nginx(nginx应该要以普通用户的身份运行)
备注:
-r:创建系统账户
-g:指定gid
-u:指定uid
3、编译安装
1)cd nginx-1.4.1
2)./configure –help|less(查看configure的帮助文档)
3)./configure \
–prefix=/usr \
–sbin-path=/usr/sbin/nginx \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/error.log \
–htp-log-path=/var/log/nginx/access.log \
–pid-path=/var/run/nginx/nginx/pid \
–lock-path=/var/lock/nginx.lock \
–user=nginx \
–group=nginx \
–with-http_ssl-module \
–with-http_flv_module \
–with-http_stub_status_module \
–with-http_gzip_static_module \
–http-client-body-temp-path=/var/tmp/nginx/client/ \
–with-proxy-temp-path=/var/tmp/nginx/proxy/ \
–with-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
–withuwsgi-temp-path=/var/tmp/nginx/uwsgi/ \
–with-scgi-temp-path=/var/tmp/nginx/scgi/ \
–with-pcre\
–with-file-aio
4)make
5)make install
备注:
如果编译出错需要重新编译,要先make clean一下再configure
以上编译选项都是两个横杠在前面
4、将nginx加入到服务列表
chkconfig –add nginx(加到服务列表中去)
chkconfig –list nginx(检查是否已经加入到服务列表)
备注:两个横杠
5、启动nginx
要想启用nginx,需要编辑一个启动脚本:/etc/rc.d/init.d/nginx #需要自己写,可以参考httpd的启动停止脚本(就是可以通过脚本来实现start|stop|reload等功能)。然后通过service nginx start来启动nginx
备注:
会在默认安装目录下创建一个html目录,里面放的就是网页文件。如果是按照上面方法提供的路径来安装nginx的话,网页文件就放在/usr/html目录中.