Ubuntu下安裝nginx的詳細(xì)步驟

本篇內(nèi)容介紹了“Ubuntu下安裝nginx的詳細(xì)步驟”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

在歙縣等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),全網(wǎng)營(yíng)銷推廣,外貿(mào)網(wǎng)站建設(shè),歙縣網(wǎng)站建設(shè)費(fèi)用合理。

1)、下載
sudo wget http://nginx.org/download/nginx-1.2.2.tar.gz

2)、解壓
sudo tar -xzvf nginx-1.2.2.tar.gz

3)、進(jìn)入相關(guān)目錄進(jìn)行以下操作

代碼如下:


./configure
make
sudo make install


如果你運(yùn)氣好的話,一切ok,不過(guò)...........哈哈。Ubuntu默認(rèn)的策略是什么庫(kù)都不裝,依賴的庫(kù)都需要自已手工安裝搞定。 一般都會(huì)出錯(cuò)的,那么我們來(lái)看看可能出現(xiàn)的問(wèn)題。

4)、常見(jiàn)問(wèn)題解決辦法
缺少pcre library
./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.   
解決方法:下載安裝pcre-8.31解決問(wèn)題,解壓后對(duì)pcre進(jìn)行如下操作

代碼如下:


sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
sudo tar -xzvf pcre-8.31.tar.gz
cd /usr/local/src/pcre-8.31
./configure
make
sudo make install


運(yùn)氣好一次通過(guò),運(yùn)氣不好,make pcre時(shí)會(huì)出錯(cuò)
缺少gcc-c++和libtool,也就是c++編譯包

代碼如下:


libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/usr/local/src//pcre-8.31'
make: *** [all] Error 2root@wolfdog-virtual-machine:~/work/pcre-8.12$ libtool -help -DHAVE_CONFIG_H
The program 'libtool' is currently not installed. You can install it by typing:
sudo apt-get install libtool


解決方法:需要先安裝libtool和gcc-c++
?sudo apt-get install libtool
sudo apt-get install gcc-c++
大爺啊~~~這時(shí)候可能又會(huì)報(bào)錯(cuò)啊,坑爹啊~~~
缺少openssl庫(kù)

代碼如下:


./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.


缺少zlib庫(kù)

代碼如下:


./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.


解決辦法:少什么就安裝什么唄。
sudo apt-get install openssl libssl-dev libperl-dev
4)、解決了以上問(wèn)題,編譯nginx就沒(méi)啥問(wèn)題了。下面安裝。(附加安裝插件的方法)
先下載插件并解壓

代碼如下:


sudo wget https://github.com/agentzh/echo-nginx-module/tarball/v0.40rc1 -O echo-nginx-module.tar.gz
sudo wget https://nodeload.github.com/agentzh/memc-nginx-module/tarball/v0.13rc3 -O memc-nginx-module.tar.gz
sudo tar -xzvf echo-nginx-module.tar.gz
sudo tar -xzvf memc-nginx-module.tar.gz


進(jìn)入nginx目錄cd nginx-1.2.2/,執(zhí)行以下命令

代碼如下:


./configure --user=www-data --group=www-data --with-debug --with-http_gzip_static_module --with-http_ssl_module --with-pcre=../pcre-8.31/ --with-http_perl_module --with-perl=/usr/bin/perl --with-http_stub_status_module --with-http_realip_module \
--prefix=/usr/local/nginx \
--add-module=../agentzh-echo-nginx-module-9259898/ \
--add-module=../agentzh-memc-nginx-module-4007350/ \
注:前面一段是一些編譯參數(shù),后面add-module是添加模塊
make -j2
make install


大爺?shù)?,又可能?bào)錯(cuò)。沒(méi)有nginx,logs目錄訪問(wèn)權(quán)限

代碼如下:


[alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2011/03/21 06:09:33 [emerg] 24855#0: mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)


解決辦法:

代碼如下:


sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx


現(xiàn)在,差不多沒(méi)問(wèn)題了。
可以進(jìn)入/usr/local/nginx/sbin/執(zhí)行以下命令看是否成功:
nginx -v
5)、nginx自啟動(dòng)
編輯啟動(dòng)腳本:

代碼如下:


sudo vim /etc/init.d/nginx

代碼如下:


#! /bin/bash
#
# nginx Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts and stops the nginx web server
### END INIT INFO
# To install:
# copy this file to /etc/init.d/nginx
# shell> chkconfig --add nginx (RedHat)
# shell> update-rc.d -f nginx defaults (debian)
# To uninstall:
# shell> chkconfig --del nginx (RedHat)
# shell> update-rc.d -f nginx remove
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/var/local/nginx/logs/$NAME.pid
ULIMIT=10240
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
echo "Starting $NAME ..."
ulimit -SHn $ULIMIT
$DAEMON -c $CONFIGFILE
}
do_stop() {
echo "Shutting down $NAME ..."
kill 'cat $PIDFILE'
}
do_reload() {
echo "Reloading $NAME ..."
kill -HUP 'cat $PIDFILE'
}
case "$1" in
start)
[ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
echo -e ".\ndone"
;;
stop)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
echo -e ".\ndone"
;;
restart)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
do_start
echo -e ".\ndone"
;;
reload)
[ -f "$PIDFILE" ] && do_reload || echo "nginx not running"
echo -e ".\ndone"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0


紅色部分,根據(jù)自己的路徑修改。

6)、常用命令

重啟nginx:service nginx restart
啟動(dòng):service nginx start
關(guān)閉:service nginx stop

7)、linux常用命令
tar(z-用 gzip 對(duì)存檔壓縮或解壓;x-從存檔展開(kāi)文件;v-詳細(xì)顯示處理的文件;f-指定存檔或設(shè)備)
tar &ndash;zxvf nginx-0.8.54.tar.gz

ip查看
ifconfig

編譯
make

安裝編譯好的源碼包
make install

編輯文件
sudo gedit /etc/profile

修改根限:chmod說(shuō)明(u:與文件屬主擁有一樣的權(quán)限[a:所有人];+:增加權(quán)限;rwx:可讀可寫可執(zhí)行)
-R:遞歸所有目錄和文件
sudo chmod a+rwx -R logs

檢查是庫(kù)是否安裝成功
dpkg --list|grep openssl

下載安裝庫(kù)
sudo apt-get install libtool

檢查服務(wù)啟動(dòng)是否正常
ps -ef|grep

查找openssl安裝路徑
whereis openssl

更新源
sudo apt-get update

更新已安裝的包
sudo apt-get upgrade

“Ubuntu下安裝nginx的詳細(xì)步驟”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

網(wǎng)頁(yè)標(biāo)題:Ubuntu下安裝nginx的詳細(xì)步驟
本文路徑:http://bm7419.com/article6/pcocig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、搜索引擎優(yōu)化網(wǎng)站營(yíng)銷、品牌網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)公司、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)