1、下載nginx
wget http://nginx.org/download/nginx-1.6.0.tar.gz
2、解壓
tar zxvf nginx-1.6.0.tar.gz
進(jìn)入nginx目錄,cd nginx-1.6.0
3、配置
./configure
配置過程中可能會報(bào)如下錯誤:
checking for PCRE library
not found
checking for PCRE library in /usr/local/
not found checking for PCRE library in /usr/include/pcre/
not found checking for PCRE library in /usr/pkg/
not found checking for PCRE library in /opt/local/
not found
./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庫,并編譯和安裝:
PCRE庫是實(shí)現(xiàn)Perl正則表達(dá)式的基礎(chǔ)。如果系統(tǒng)中缺少此庫需要編譯安裝。可以從著名的開源軟件網(wǎng)站sourceforge上下載:
http://sourceforge.net/projects/pcre/files/pcre/。
仍然是下載后解壓、配置、編譯和安裝:
[***]tar -zxvf pcre-8.35.tar.gz
[***]cd pcre-8.35
[***]./configure
[***]make
[***]make install
4、編譯與安裝nginx
make
make install
5、啟動nginx
/usr/local/nginx/sbin/nginx
注:在64位系統(tǒng)上啟動時有可能報(bào)如下錯誤:
Nginx: error while loading shared libraries: libpcre.so.1
解決辦法如下:
ln -s /usr/local/lib/libpcre.so.1 /lib64/libpcre.so.1
再將啟動即可。
6、查看是否啟動成功
[root@localhost ~]# ps -aef | grep nginx
root 28295 1 0 22:52 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 28296 28295 0 22:52 ? 00:00:00 nginx: worker process
root 28615 28587 0 23:09 pts/0 00:00:00 grep nginx
[root@localhost ~]#
啟動成功,master是主進(jìn)程,關(guān)閉的時候kill這個進(jìn)程,其他子進(jìn)程會自動關(guān)掉
打開瀏覽器http://localhost/ 即可看到nginx的默認(rèn)歡迎頁
Welcome to nginx!