linux非root用户安装nginx

Posted wuxun1997

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 

  开始编译前检查:

$ cd nginx-1.16.1/
$ ./configure --prefix=/home/wlf/nginx --with-http_stub_status_module

  其中参数http_stub_status_module是开启stub_status模块,它主要用于查看Nginx的一些状态信息。检查结果:

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/home/wlf/nginx"
  nginx binary file: "/home/wlf/nginx/sbin/nginx"
  nginx modules path: "/home/wlf/nginx/modules"
  nginx configuration prefix: "/home/wlf/nginx/conf"
  nginx configuration file: "/home/wlf/nginx/conf/nginx.conf"
  nginx pid file: "/home/wlf/nginx/logs/nginx.pid"
  nginx error log file: "/home/wlf/nginx/logs/error.log"
  nginx http access log file: "/home/wlf/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"

  开始编译和安装:

$ 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 

 

以上是关于linux非root用户安装nginx的主要内容,如果未能解决你的问题,请参考以下文章

linux 非root 用户安装redis 安装

Linux 非root 用户安装openresty

Linux 非root用户安装cuda和cudnn

Linux 非root用户安装cuda和cudnn

linux CUDA安装(非ROOT用户)

linux非root用户安装perl及其基本用法