天天看点

centos6 编译安装nginx

1.为nginx新建组和用户

groupadd -g 80 www

useradd -u 80 -g 80 -s /sbin/nologin www

2.安装需要的库

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

3.获取源码(以1.12.1为例)

打开官方网站进行下载

http://nginx.org/en/download.html

mkdir -p /data/soft/

cd /data/soft

注:随着版本的升级以下下载连接会失效,替换新的下载连接即可

wget http://219.239.26.13/files/205400000A6F9D7F/nginx.org/download/nginx-1.12.1.tar.gz

tar xf nginx-1.12.1.tar.gz 

4.安全处理

cd /data/soft/nginx-1.12.1/src/core/

sed -i "s/\"nginx\/\"\ NGINX_VERSION/\"nProxy\"/g" nginx.h 

cd /data/soft/nginx-1.12.1/src/http

sed -i "s/Server: nginx/Server: nProxy/g" ngx_http_header_filter_module.c

sed -i "s/center>nginx/center>nProxy/g" ngx_http_special_response.c 

5.编译安装

cd /data/soft/nginx-1.12.1

./configure --user=www --group=www --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-select_module --with-poll_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --with-pcre

make && make install

6.检查语法启动

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx

7.设置开机自启动

echo '/usr/local/nginx/sbin/nginx' >> /etc/rc.local

本文转自younger00851CTO博客,原文链接: http://blog.51cto.com/younger008/1899270,如需转载请自行联系原作者

继续阅读