微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐