linux非root用户安装nginx

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

linux非root用户安装nginx

 

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

linux非root用户安装nginx
$ 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 
linux非root用户安装nginx

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

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

linux非root用户安装nginx

 

 

linux非root用户安装nginx

 

   退出当前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的一些状态信息。后面两个用来指定两个依赖的源码目录。检查结果:

linux非root用户安装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"
linux非root用户安装nginx

 

  检查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:

linux非root用户安装nginx
    #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;
        }
linux非root用户安装nginx

  重新启动后发现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 
上一篇:RESTful是什么


下一篇:内置函数--eval