CentOS 7 编译安装Nginx

来源:互联网 发布:罗斯文数据库 编辑:程序博客网 时间:2024/05/19 17:26
一、准备工作:
1、安装必备工具:
$ yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel
说明:
pcre: 用来作地址重写的功能。
zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。
openssl:提供ssl加密协议。


2、安装之前,最好检查一下是否已经安装有nginx
$ find -name nginx 
如果系统已经安装了nginx,那么就先卸载                                                                                                                      
$ yum remove nginx  
如果系统已经安装了nginx,那么就先卸载                                                                                                                      


二、Nginx编译安装:
1、下载Nginx:http://nginx.org/en/download.html
$   cd /usr/local
$   wget http://nginx.org/download/nginx-1.13.0.tar.gz 
2、解压编译:
$ tar -zxvf nginx-1.13.0.tar.gz
$ cd nginx-1.13.0/


$ ./configure \
--prefix=/home/programs/nginx \
--sbin-path=/home/programs/nginx/sbin/nginx \
--conf-path=/home/programs/nginx/nginx.conf \
--error-log-path=/home/programs/nginx/custdata/logs/error.log \
--http-log-path=/home/programs/nginx/custdata/logs/access.log \
--pid-path=/home/programs/nginx/custdata/run/nginx.pid \
--lock-path=/home/programs/nginx/custdata/lock/nginx.lock \
--user=nginx --group=nginx  \
--http-client-body-temp-path=/home/programs/nginx/custdata/tmp/client_temp \
--http-proxy-temp-path=/home/programs/nginx/custdata/tmp/proxy_temp \
--http-fastcgi-temp-path=/home/programs/nginx/custdata/tmp/fastcgi_temp \
--http-uwsgi-temp-path=/home/programs/nginx/custdata/tmp/uwsgi_temp \
--http-scgi-temp-path=/home/programs/nginx/custdata/tmp/scgi_temp \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-file-aio \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'


上面的参数的作用可以通过--help来查看下文附加1中有提供




3、安装:
$ make && make install
4、启动:

$ /home/programs/nginx/sbin/nginx

如果没有nginx用户,需要增加

useradd -s /sbin/nologin -M nginx



5、其它:
停止:
$ /home/programs/nginx/sbin/nginx -s stop 
查看版本及安装的模块(大写的V):
$ /home/programs/nginx/sbin/nginx -V
原创粉丝点击