zoukankan      html  css  js  c++  java
  • linux非root用户安装nginx

      先到官网http://nginx.org/en/download.html下载最新稳定版源码包,目前是1.16.1:

       下完后通过rz上传至wlf用户soft目录下,退回上一级目录解压:

    $ cd soft
    $ rz -y
    rz waiting to receive.
    开始 zmodem 传输。  按 Ctrl+C 取消。
      100%    1008 KB 1008 KB/s 00:00:01       0 Errors
    $ cd ..
    $ tar xzvf soft/nginx-1.16.1.tar.gz 

      在开始nginx检查前,我们还需要装两个依赖:pcre和zlib。

      同上面流程,分别到ftp://ftp.pcre.org/pub/pcre/http://www.zlib.net/下载pcre-8.43.zip(注意别下pcre2)和zlib-1.2.11.zip:

       退出当前soft目录,分别解压安装:

    $ cd ..
    $ unzip soft/pcre-8.43 $ cd pcre
    -8.43 $ ./configure --prefix=/home/wlf/pcre $ make && make install
    $ cd ..
    $ unzip soft/zlib-1.2.11
    $ cd zlib-1.2.11
    $ ./configure --prefix=/home/wlf/zlib
    $ make && make install

       两个依赖都装好后,可以开始正式的nginx编译前检查:

    $ cd nginx-1.16.1/
    $ ./configure --prefix=/home/wlf/nginx --with-http_stub_status_module --with-pcre=/home/wlf/pcre-8.43 --with-zlib=/home/wlf/zlib-1.2.11

      其中参数http_stub_status_module是开启stub_status模块,它主要用于查看Nginx的一些状态信息。后面两个用来指定两个依赖的源码目录。检查结果:

    Configuration summary
      + using PCRE library: /home/mgwh/pcre-8.43
      + OpenSSL library is not used
      + using zlib library: /home/mgwh/zlib-1.2.11
    
      nginx path prefix: "/home/mgwh/nginx"
      nginx binary file: "/home/mgwh/nginx/sbin/nginx"
      nginx modules path: "/home/mgwh/nginx/modules"
      nginx configuration prefix: "/home/mgwh/nginx/conf"
      nginx configuration file: "/home/mgwh/nginx/conf/nginx.conf"
      nginx pid file: "/home/mgwh/nginx/logs/nginx.pid"
      nginx error log file: "/home/mgwh/nginx/logs/error.log"
      nginx http access log file: "/home/mgwh/nginx/logs/access.log"
      nginx http client request body temporary files: "client_body_temp"
      nginx http proxy temporary files: "proxy_temp"
      nginx http fastcgi temporary files: "fastcgi_temp"
      nginx http uwsgi temporary files: "uwsgi_temp"
      nginx http scgi temporary files: "scgi_temp"

      检查ok,编译和安装一般没问题:

    $ make && make install

      启动nginx:

    $ cd ~
    $ cd nginx
    $ sbin/nginx 
    nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

      报错原因:在linux下,普通用户只能用1024以上的端口,而1024以内的端口只能由root用户才可以使用,所以这里80端口只能由root才能使用。

      我们通过vi修改下配置文件conf/nginx.conf,将端口改成8787:

        #gzip  on;
    
        server {
            listen       8787;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }

      重新启动后发现nginx已经起好了:

    $ netstat -nlp | grep 8787
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp        0      0 0.0.0.0:8787            0.0.0.0:*               LISTEN      29950/nginx: master 
  • 相关阅读:
    Android复习(五)设备兼容—>多apk支持
    Android复习(五)设备兼容—>支持刘海屏
    KVC给只读属性进行赋值..
    pods 终端安装 第三方框架的一些命令
    使用SnakeKit怎么设置动画效果 以及 UIView的弹簧动画效果
    Cocoa、Foundation、UIKit、Objective-c、XCode、Interface Builder的概念
    仿写SDWebImage中的一个网络加载图片的框架
    TCP/IP 短链接 长链接 scoket
    init 和 initWithFrame 区别
    JSON XML 数据解析
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/11583641.html
Copyright © 2011-2022 走看看