Linux 下安裝配置nginx及常見問題解答

其實也不能完全算是原創吧!都是我配置nginx時所遇到的問題,查閱資料後總結起來。即是鞏固一下nginx的配置,也是分享給新入Linux的童鞋們一些知識

好了,不多廢話,進入主題吧!

爲nginx添加www組及www用戶

[root@hostname ~ ]groupadd www      //添加www組
[root@hostname ~ ]useradd -g www www  //添加www用戶並加入www組

注:如果給groud、passwd等文件添加過不可更改屬性,需要先取消權限鎖定設置

編譯安裝

[root@hostname ~ ]tar zxvf nginx-1.8.0.tar.gz  //解壓包
[root@hostname ~ ]./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --user=www --group=www //安裝nginx到/usr/local/下,設置配置文件路徑及用戶
[root@hostname ~ ]make
[root@hostname ~ ]make install

對於nginx軟件包,個人建議從官網下載


 

錯誤信息及解決方法

進行到 ./configure這一步時報錯,解決方法如下:

1)如果報錯
./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依賴

[root@hostname ~]tar zxvf pcre-8.12.tar.gz
[root@hostname ~]cd pcre-8.12
[root@hostname ~]./configure
[root@hostname ~]make
[root@hostname ~]make install

   2)如果報錯

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

  同上、zlib-devel依賴沒安裝或安裝失敗 。安裝zlib-devel依賴

[root@hostname ~]yum install -y zlib-devel //也可以軟件包安裝

  這時再進行./configure make make install 即可完成安裝。

 

啓動nginx 

[root@hostname ~]/usr/local/nginx/sbin/nginx /usr/local/nginx/conf/nginx.conf

  如果報異常如下,說明我們環境還沒有完全配置好

[root@hostname ~]/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

  解決方法:進入lib目錄下,直接輸入

[root@hostname lib]ln -s /usr/local/lib/libpcre.so.1 /lib     //32位系統
[root@hostname lib]ln -s /usr/local/lib/libpcre.so.1 /lib64   //64位系統

       再啓動nginx,沒有報錯信息,查看nginx進程(至少要有一個master一個worker)

[root@hostname ~]$ ps -aux | grep nginx
root 15913  0.0  0.0  19804   628 ?  Ss  11:58  0:00 nginx: master process /usr/local/nginx/sbin/nginx
www 15914  1.9  0.0  20720  2068 ?  S  11:58  3:11 nginx: worker process

  到這一步,nginx就已經配置成功了

 

  Tips:非root用戶不要忘記使用sudo進行上面的操作

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章