1:檢查pcre是否安裝,安裝pcre庫是為了使Nginx支援具備URL重寫的rewrite子產品.openssl是nginx使用https服務要用的子產品。
<code>rpm -qa|</code><code>grep</code> <code>-E </code><code>'pcre|pcre-devel'</code>
<code># 如果無傳回結果,證明pcre包未安裝,使用以下指令下載下傳安裝</code>
<code>yum </code><code>install</code> <code>pcre pcre-devel -y</code>
<code>rpm -qa|</code><code>grep</code> <code>-E </code><code>'openssl|openssl-devel'</code>
<code># 如果傳回值為空,表示系統尚未安裝,安裝指令如下</code>
<code>yum </code><code>install</code> <code>openssl openssl-devel</code>
<code>rpm -qa |</code><code>grep</code> <code>gcc gcc-c++</code>
<code># 如果未安裝gcc,則編譯過程中會出現./configure: error: C compiler cc is not found錯誤</code>
<code>yum </code><code>install</code> <code>gcc gcc-c++</code>
2:安裝nginx1-11-11
<code>wget -q -P </code><code>/tmp/</code>
<code># 将nginx指定下載下傳到目前目錄下,-q表示斷電斷續</code>
<code>tar</code> <code>-zxvf </code><code>/tmp/nginx-1</code><code>.11.11.</code><code>tar</code><code>.gz -C </code><code>/usr/local/src/</code>
<code># 将軟體固定存放在/usr/local/src/下</code>
<code>useradd</code> <code>nginx -s </code><code>/sbin/nologin</code> <code>-M</code>
<code>cd</code> <code>/usr/local/src/nginx-1</code><code>.11.11</code>
<code>.</code><code>/configure</code> <code>--user=nginx --group=nginx --prefix=</code><code>/usr/local/nginx-1</code><code>.11.11/ --with-http_stub_status_module --with-http_ssl_module</code>
<code># 編譯參數說明:</code>
<code># --prefix=PATH # 設定安裝路徑</code>
<code># --user=user --group=group # 設定運作nginx的使用者和使用者組</code>
<code># --with-http_stub_status_module # 激活狀态資訊</code>
<code># --with-http_ssl_module # 激活ssl功能</code>
<code># Nginx的大部分子產品功能都會編譯到軟體中,不需要單獨指定編譯參數 </code>
<code>echo</code> <code>$?</code>
<code>make</code> <code>&& </code><code>make</code> <code>install</code>
<code>ln</code> <code>-s </code><code>/usr/local/nginx-1</code><code>.11.11 </code><code>/usr/local/nginx</code>
<code># 設立一條軟連接配接,好處是程式中如果有引用nginx路徑的地方,不需要修改程式,如果更新nginx版本</code>
<code>直接重新做一條連接配接即可</code>
3:啟動并檢查安裝結果
<code>[root@C-A nginx-1.11.11]</code><code># /usr/local/nginx/sbin/nginx -t</code>
<code>nginx: the configuration </code><code>file</code> <code>/usr/local/nginx-1</code><code>.11.11</code><code>//conf/nginx</code><code>.conf syntax is ok</code>
<code>nginx: configuration </code><code>file</code> <code>/usr/local/nginx-1</code><code>.11.11</code><code>//conf/nginx</code><code>.conf </code><code>test</code> <code>is successful</code>
<code># 在啟動之前檢查文法非常重要,可防止因配置錯誤導緻網站重新開機或重新加載配置等對使用者的影響。</code>
<code>[root@C-A nginx-1.11.11]</code><code># /usr/local/nginx/sbin/nginx</code>
<code># 啟動nginx服務</code>
<code>[root@C-A nginx-1.11.11]</code><code># lsof -i :80</code>
<code>COMMAND PID USER FD TYPE DEVICE SIZE</code><code>/OFF</code> <code>NODE NAME</code>
<code>nginx 18360 root 6u IPv4 45635 0t0 TCP *:http (LISTEN)</code>
<code>nginx 18361 nginx 6u IPv4 45635 0t0 TCP *:http (LISTEN)</code>
<code>[root@C-A nginx-1.11.11]</code><code># netstat -lnp|grep 80</code>
4:Nginx啟動的疑難雜症彙總
問題1:啟動Nginx時有如下報錯“nginx:[emerg] getpwnam("nginx")failed".
解答:這是因為沒有對應的Nginx服務使用者,執行useradd -s /sbin/nologin -M建立nginx使用者即可。
<code>[root@C-A nginx-1.11.11]</code><code># pkill nginx</code>
<code>[root@C-A nginx-1.11.11]</code><code># userdel nginx</code>
<code>nginx: [emerg] getpwnam(</code><code>"nginx"</code><code>) failed</code>
<code>[root@C-A nginx-1.11.11]</code><code># useradd -s /sbin/nologin -M nginx</code>
<code>正在建立信箱檔案: 檔案已存在</code>
<code>nginx 22812 root 6u IPv4 54655 0t0 TCP *:http (LISTEN)</code>
<code>nginx 22813 nginx 6u IPv4 54655 0t0 TCP *:http (LISTEN)</code>
<code>[root@C-A nginx-1.11.11]</code><code>#</code>
問題2:如何檢視編譯安裝nginx時的參數
解答:可采用如下指令
<code>[root@C-A nginx-1.11.11]</code><code># /usr/local/nginx/sbin/nginx -V</code>
<code>nginx version: nginx</code><code>/1</code><code>.11.11</code>
<code>built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)</code>
<code>built with OpenSSL 1.0.1e-fips 11 Feb 2013</code>
<code>TLS SNI support enabled</code>
<code>configure arguments: --user=nginx --group=nginx --prefix=</code><code>/usr/local/nginx-1</code><code>.11.11/ --with-http_stub_status_module --with-http_ssl_module</code>
問題3:curl,浏覽器等無法通路Nginx頁面
解答:此類問題排查思路分在服務端和用戶端,服務端可排查防火牆是否放行nginx端口。程序是否存在,程序啟動的是否是80端口。用戶端可排查是否Ping通伺服器,telnet檢查是否可連服務端80端口。
本文轉自 運維國小生 51CTO部落格,原文連結:http://blog.51cto.com/yasar/1909681,如需轉載請自行聯系原作者