ubuntu 15.04 手动安装nginx 1.9.0

1 篇文章 0 订阅
平时工作也用nginx,不过用的时候都是已经配好的,只要简单改改参数就可以了。今天在自己的电脑上安装的时候发现没有想象的那么顺利。
纸上得来终觉浅,绝知此事要躬行。
正题:
        1、到nginx下载页面获取最新版本的包(截止发文日期,最新版本是nginx-1.9.0):
              地址http://nginx.org/en/download.html,也可以在命令行下直接 wget http://nginx.org/download/nginx-1.9.0.tar.gz
        2、解压tar -zxvf nginx-1.9.0.tar.gz,命令行进入解压目录运行:./configure
              在安装过程可能会提示如下两个错误:
                      ./configure: error: the HTTP rewrite module requires the PCRE library
                     ./configure: error: the HTTP gzip module requires the zlib library.
              解决方法如下:
                     sudo apt-get install libpcre3 libpcre3-dev
                     sudo apt-get install zlib1g-dev
       3、运行 make
       4、运行 sudo make install
       5、ok至此nginx安装完成。
       6、下面进入目录/usr/local/nginx/ 运行./sbin/nginx。提示错误:
                 nginx: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
                 mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)
                 ll命令查看是权限问题,再执行sudo ./sbin/nginx,没有报错。ps -ef | grep nginx看一下,有两个线程master process 和 worker process。跟官方文档描述的一致。

      7、浏览器打开http://localhost,nginx welcome 如约而现。

      8、不能每次启动都是用sudo,并且日志输出也会出问题,所以我们可以把nginx目录授权:

               sudo chmod a+rwx -R logs  

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

               再次运行发现依然报错:nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied),默认监听80端口,在网上查了后发现是这个原因导致的:http://serverfault.com/questions/84360/regular-user-using-ports-below-1024。

               不想root运行的解决办法是修改监听端口为大于1024。


      如果不用root运行只能修改iptable了,修改监听端口为大于1024的值,再映射到80端口。感觉别扭。那我直接就监听访问ip对应端口就好了,何必如此。。So,不考虑此种方法,有好方式感谢告知!!

      另外网上也有说用setcap cap_net_bind_service、AuthBind的,都需要安装软件支持,与初衷不符合。So,pass。


   PS:之前有通过ubuntu soft center安装nginx,并且有误删除操作的而导致无法重新安装nginx的情况,可以使用如下命令清除干净,再执行以上3-8步:

        sudo apt-get remove --purge nginx-common


附上从官网爬来的文档:

http://download.csdn.net/detail/array7/8678095

参考资料:

1、http://stackoverflow.com/questions/18480201/ubuntu-nginx-emerg-bind-to-0-0-0-080-failed-13-permission-denied

2、http://peterwei.iteye.com/blog/969991

3、http://serverfault.com/questions/84360/regular-user-using-ports-below-1024

4、http://zhiwei.li/text/2012/01/%E9%9D%9Eroot%E7%94%A8%E6%88%B7%E8%BF%90%E8%A1%8C%E7%9A%84%E7%A8%8B%E5%BA%8F%E5%A6%82%E4%BD%95%E7%9B%91%E5%90%AC%E5%9C%A880%E4%BB%A5%E5%8F%8A%E5%85%B6%E4%BB%96%E7%89%B9%E6%9D%83%E7%AB%AF%E5%8F%A3/



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值