CentOS 6.5 Nginx 配置


1.安裝所有 http功能

./configure --user=www-data --group=www-data --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module

錯誤:

./configure: error: the HTTP image filter module requires the GD library.

./configure: error: the GeoIP module requires the GeoIP library

1.1 安裝 GeoIP (區分大小寫)

yum install GeoI GeoIP-data GeoIP-devel

完畢以后,還需要到MaxMind去下一個GeoCityLite,待會php程序要用到。

下載地址是:http://geolite.maxmind.com/downl ... /GeoLiteCity.dat.gz
下載完畢以后,將壓縮包解壓出數據庫的.dat文件,並把文件重命名為GeoIPCity.dat,然后移動到GeoIP的數據文件夾下。
使用 whereis GeoIP查看位置在 /usr/share
 
gzip -d GeoLiteCity.dat.gz
mv GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
參考:
 

1.2 安裝gd

yum install gd-devel

參考:http://www.cnblogs.com/tintin1926/archive/2012/07/11/2586624.html

 

1.3帳號用戶配置

--user=www-data --group=www-data 表示帳號和用戶, 這兩個應該都是已經存在的, 若不存在則在配置晚Nginx后需要添加這兩個帳號或者修改 nginx.conf配置為user nobody, 詳細見 4.1

至此,configure 成功

2. make

沒有出現錯誤提示;成功。

出現 make[1]: Leaving directory `/home/gxw/Downloads/nginx-1.6.0'

3. make install

沒出先錯誤提示, 成功。

安裝路徑為:/usr/local/nginx/

出現

[root@localhost nginx-1.6.0]# make install
make[1]: Leaving directory `/home/gxw/Downloads/nginx-1.6.0'

 

4 安裝后運行出現的錯誤:

4.1 [root@localhost sbin]# ./nginx
nginx: [emerg] getpwnam("www-data") failed

原因: 沒有創建www這個用戶

解決:

4.1.1 添加www用戶組和用戶www,如下命令:

#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www
4.2.1 更改設置:
http://www.iitshare.com/install-nginx-nginx-emerg-getpwnam-www-failed-error.html
 在nginx.conf中
把user nobody的注釋去掉既可 
或者
nobody 更改為已有帳號:gxw
[root@localhost conf]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
第1行: # user  nobody;  去掉注釋即刪除#
改為: user  nobody;
 
4.2 nginx.conf錯誤
[emerg] invalid number of arguments in "user" directive in /usr/local/nginx/conf/nginx.conf:4
發現: /usr/local/nginx/conf/nginx.conf 文件中
第3行, user nobody 少了; 結尾。
user nobody;
   

添加; 后,測試成功。顯示為:

[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

4.3 普通用戶 gxw無法啟動nginx

4.3.1 出現錯誤:

  [gxw@localhost sbin]$ ./nginx
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2014/07/01 21:12:13 [warn] 4882#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:2
2014/07/01 21:12:13 [emerg] 4882#0: open() "/usr/local/nginx/logs/access.log" failed (13: Permission denied)
原因是:
默認情況下linux的1024以下端口是只有root用戶才有權限占用

而gxw:gxw屬於gxw組布局被root權限。

並且Log文件也是root權限。gxw也不具備。

4.3.2解決:

 

方法一采用了該方法

 

所有用戶都可以運行(因為是755權限,文件所有者:root,組所有者:root)

 

chown root:root nginx

 

chmod 755 nginx

 

chmod u+s nginx

 

 

 

方法二:

 

僅 root 用戶和 reistlin 用戶可以運行(因為是750權限,文件所有者:root,組所有者:www)

 

chown root:www nginx

 

chmod 750 nginx

 

chmod u+s nginx

 

 

 

5. 成功運行

進入:/usr/local/nginx/sbin/

[root@localhost sbin]# ./nginx    開啟Nginx

打開瀏覽器輸入:127.0.0.1

顯示頁面:

 

 

6. 使用命令

/usr/local/nginx/nginx -V  查看版本 和 配置信息(編譯前的 --with-** 配置)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM