天天看點

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,如需轉載請自行聯系原作者

繼續閱讀