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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM