Nginx源碼安裝

原文:http://www.nginx.cn/install
html

1、nginx安裝
一、配置編譯環境
yum -y install gcc automake autoconf libtool make
yum install gcc

二、通常現須要安裝pcre(重寫rewrite)、zlib(gzip壓縮)、ssl
2.1安裝pcre
(1)下載
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
(2)解壓
tar -zxvf pcre-8.38.tar.gz
(3)進入目錄
cd pcre-8.38
(4)安裝
./configure        
make    
make install

2.2安裝zlib
(1)下載
wget http://zlib.net/zlib-1.2.8.tar.gz
(2)解壓
tar -zxvf zlib-1.2.8.tar.gz
(3)進入目錄
cd zlib-1.2.8
(4)安裝
./configure        
make    
make install
2.3安裝ssl
(1)下載
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
(2)解壓
tar -zxvf openssl-1.0.1c.tar.gz
(3)進入目錄
cd  openssl-1.0.1c
(4)安裝
./configure        
make    
make install

3安裝nginx
3.1下載
wget http://nginx.org/download/nginx-1.10.0.tar.gz
tar -zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0
./configure --sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with-pcre=/root/src/pcre-8.38 //指的源碼路徑
--with-zlib=/root/src/zlib-1.2.8
--with-openssl=/root/src/openssl-1.0.1c
make
make install

//至此安裝完成

4啓動
/usr/local/nginx/nginx

//查看是否運行
netstat -ano | grep 80
ps -ef | grep nginx
nginx


//編譯
正則表達式

make是用來編譯的,它從Makefile中讀取指令,而後編譯。

make install是用來安裝的,它也從Makefile中讀取指令,安裝到指定的位置。

configure命令是用來檢測你的安裝平臺的目標特徵的。它定義了系統的各個方面,包括nginx的被容許使用的鏈接處理的方法,好比它會檢測你是否是有CC或GCC,並非須要CC或GCC,它是個shell腳本,執行結束時,它會建立一個Makefile文件。nginx的configure命令支持如下參數:

--prefix=path    定義一個目錄,存放服務器上的文件 ,也就是nginx的安裝目錄。默認使用 /usr/local/nginx。
--sbin-path=path 設置nginx的可執行文件的路徑,默認爲  prefix/sbin/nginx.
--conf-path=path  設置在nginx.conf配置文件的路徑。nginx容許使用不一樣的配置文件啓動,經過命令行中的-c選項。默認爲prefix/conf/nginx.conf.
--pid-path=path  設置nginx.pid文件,將存儲的主進程的進程號。安裝完成後,能夠隨時改變的文件名 , 在nginx.conf配置文件中使用 PID指令。默認狀況下,文件名 爲prefix/logs/nginx.pid.
--error-log-path=path 設置主錯誤,警告,和診斷文件的名稱。安裝完成後,能夠隨時改變的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默認狀況下,文件名 爲prefix/logs/error.log.
--http-log-path=path  設置主請求的HTTP服務器的日誌文件的名稱。安裝完成後,能夠隨時改變的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默認狀況下,文件名 爲prefix/logs/access.log.
--user=name  設置nginx工做進程的用戶。安裝完成後,能夠隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的用戶名是nobody。
--group=name  設置nginx工做進程的用戶組。安裝完成後,能夠隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的爲非特權用戶。
--with-select_module --without-select_module 啓用或禁用構建一個模塊來容許服務器使用select()方法。該模塊將自動創建,若是平臺不支持的kqueue,epoll,rtsig或/dev/poll。
--with-poll_module --without-poll_module 啓用或禁用構建一個模塊來容許服務器使用poll()方法。該模塊將自動創建,若是平臺不支持的kqueue,epoll,rtsig或/dev/poll。
--without-http_gzip_module — 不編譯壓縮的HTTP服務器的響應模塊。編譯並運行此模塊須要zlib庫。
--without-http_rewrite_module  不編譯重寫模塊。編譯並運行此模塊須要PCRE庫支持。
--without-http_proxy_module — 不編譯http_proxy模塊。
--with-http_ssl_module — 使用https協議模塊。默認狀況下,該模塊沒有被構建。創建並運行此模塊的OpenSSL庫是必需的。
--with-pcre=path — 設置PCRE庫的源碼路徑。PCRE庫的源碼(版本4.4 - 8.30)須要從PCRE網站下載並解壓。其他的工做是Nginx的./ configure和make來完成。正則表達式使用在location指令和 ngx_http_rewrite_module 模塊中。
--with-pcre-jit —編譯PCRE包含「just-in-time compilation」(1.1.12中, pcre_jit指令)。
--with-zlib=path —設置的zlib庫的源碼路徑。要下載從 zlib(版本1.1.3 - 1.2.5)的並解壓。其他的工做是Nginx的./ configure和make完成。ngx_http_gzip_module模塊須要使用zlib 。
--with-cc-opt=parameters — 設置額外的參數將被添加到CFLAGS變量。例如,當你在FreeBSD上使用PCRE庫時須要使用:--with-cc-opt="-I /usr/local/include。.如須要須要增長 select()支持的文件數量:--with-cc-opt="-D FD_SETSIZE=2048".
--with-ld-opt=parameters —設置附加的參數,將用於在連接期間。例如,當在FreeBSD下使用該系統的PCRE庫,應指定:--with-ld-opt="-L /usr/local/lib".shell


原文:http://www.cnblogs.com/jianxie/p/3990377.html服務器

2、nginx啓動、重啓、關閉
一、啓動  
/usr/local/nginx/sbin/nginx
二、重啓
更改配置重啓nginx  
kill -HUP 主進程號或進程號文件路徑
或者使用
/usr/local/nginx/sbin/nginx -s reloadide

/usr/local/nginx/sbin/nginx -s strop網站

/usr/local/nginx/sbin/nginx -s quit
ui

/usr/local/nginx/sbin/nginx -s reopenspa

判斷配置文件是否正確 
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
/usr/local/nginx/sbin/nginx -t
三、關閉
查詢nginx主進程號
ps -ef | grep nginx
從容中止   kill -QUIT 主進程號
快速中止   kill -TERM 主進程號
強制中止   kill -9 nginx
若nginx.conf配置了pid文件路徑,若是沒有,則在logs目錄下
kill -信號類型 '/usr/local/nginx/logs/nginx.pid'.net

相關文章
相關標籤/搜索