天天看點

普通使用者安裝Nginx

一、安裝前準備

安裝包擷取

Nginx網站http://nginx.org 下載下傳軟體版本包

目前主流版本為nginx-1.13.3   穩定版本為nginx-1.12.1,這裡使用穩定版nginx-1.12.1 為例

1、安裝pcre軟體包

安裝pcre庫是為使Nginx支援HTTP rewrite子產品

在Linux系統中檢視pcre軟體包是否已經安裝,如果沒有請事先安裝好,在CD光牒裡面可以使用rpm -ivh 安裝

[root@iccsdb02 tmp]# rpm -qa | grep pcre

pcre-7.8-7.el6.x86_64

錯誤提示:./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

解決辦法:

yum -y install  pcre-devel-7.8-6.el6.x86_64

2、安裝openssl-devel軟體包

錯誤提示:./configure: error: the HTTP cache module requires md5 functions

from OpenSSL library.   You can either disable the module by using

--without-http-cache option, or install the OpenSSL library into the system,

or build the OpenSSL library statically from the source with nginx by using

--with-http_ssl_module --with-openssl=<path> options.

yum  -y install openssl openssl-devel

3、建立應用Nginx軟體的應用使用者

lvcreate  -L 1G -n lv_iccs apvg

mkfs.ext4 /dev/apvg/lv_iccs 

編輯/etc/fstab 裡面實作自動挂載

4、建立應用使用者

useradd  -u 601 -d /home/iccs iccs

chown iccs:iccs -R /home/iccs

5、解壓軟體包并賦權給應用使用者

tar -xvf nginx-1.12.1.tar.gz

chown iccs:iccs -R /tmp/nginx-1.12.1

二、安裝Nginx軟體

1、使用configure 指令可以檢測軟體的安裝環境,并生成Makefile檔案

su - iccs

cd /tmp/nginx-1.12.1

./configure\

> --user=iccs \

> --group=iccs \

> --prefix=/home/iccs \

> --sbin-path=/home/iccs/sbin/nginx \

> --conf-path=/home/iccs/conf/nginx.conf \

> --error-log-path=/home/iccs/log/error.log \

> --http-log-path=/home/iccs/log/access.log \

> --http-client-body-temp-path=/home/iccs/tmp/client_body \

> --http-proxy-temp-path=/home/iccs/tmp/proxy \

> --http-fastcgi-temp-path=/home/iccs/tmp/fastcgi \

> --pid-path=/home/iccs/var/run/nginx.pid \

> --lock-path=/home/iccs/var/lock/subsys/nginx \

> --with-http_stub_status_module \

> --with-http_ssl_module \

> --with-http_gzip_static_module 

備注:

configure 選項                                    【選項含義】

--user                                            指定啟動程式所屬使用者

--group                                            指定啟動程式所屬組

--prefix                                              指定nginx安裝路徑

--sbin-path                                    設定nginx二進制檔案的路徑

--conf-path                                    指定配置檔案的路徑

--error-log-path                            指定錯誤日志檔案路徑

--http-log-path                            指定通路日志檔案路徑

--http-client-body-temp-path    設定存儲HTTP用戶端請求主體的臨時檔案路徑

--http-proxy-temp-path                    設定存儲HTTP代理臨時檔案的路徑

--pid-path                                    設定nginx.pid檔案路徑

--lock-path                                    設定nginx.lock 檔案路徑

--with-openssl                            啟用SSL

--with-pcre                                    啟用正規表達式

--with-http_stub_status_module      安裝可以監控nginx狀态的子產品

--with-http_ssl_module                    啟用SSL支援

--with-http_gzip_static_module    啟用gzip壓縮

2、開始安裝

[iccs@iccsdb02 nginx-1.12.1]$ make 

[iccs@iccsdb02 nginx-1.12.1]$ make install

三、啟動Nginx 

[iccs@iccsdb02 sbin]$ ./nginx 

nginx: [emerg] mkdir() "/home/iccs/tmp/client_body" failed (2: No such file or directory)

nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

備注:這裡啟動的時候遇到兩個錯誤

1、因為在目錄下面沒有找到tmp目錄,是以無法寫入緩存檔案

2、因為我們是應用使用者安裝并且啟動的,在Linux系統下普通使用者是不能使用1024以下端口的,而Nginx預設是80端口,是以需要修改/home/iccs/conf/nginx.conf配置檔案将端口改為1024以上,我這裡改為了1983

3、如果你是root安裝的話,在啟動nginx之前,也一定要確定停止其它web服務如Apache等服務沖突防止端口

5、檢視nginx程序和端口, 和之前配置檔案worker process 一共8個,和配置檔案中一樣

<a href="https://s5.51cto.com/wyfs02/M00/9C/64/wKiom1lwCz-xJg4qAACKIN51xYc979.jpg" target="_blank"></a>

6、Nginx 啟動常用選項

Nginx       [選項]

-p          &lt;字首&gt;設定字首路徑,預設為/opt/nginx

-c          &lt;檔案名&gt;設定配置檔案,預設為/etc/nginx/nginx.conf

-v        顯示版本資訊并退出

-V        顯示版本資訊和配置選項,然後退出

-t        測試配置時候正确,并退出

-q        配置測試過程中抑制非錯誤資訊

-s          &lt;信号&gt;将stop、quit、reopen、reload等信号發送給nginx主程序

直接啟動服務執行 /home/iccs/sbin/nginx 

為了友善加入一下應用使用者的環境變量

vim /home/icccs/.bash_profile 将指令路徑變成如下

PATH=$PATH:$HOME/bin:$HOME/sbin

本文轉自 yuri_cto 51CTO部落格,原文連結:http://blog.51cto.com/laobaiv1/1949037,如需轉載請自行聯系原作者

繼續閱讀