編譯安裝NGINX-1.21.0


官網:http://nginx.org/en/download.html

下載地址:http://nginx.org/download/nginx-1.21.0.tar.gz

一、編譯前提,需要安裝必要的包

yum install gcc pcre-devel openssl-devel zlib-devel wget -y

(wget不是編譯必須的,只是我后面要下載東西用,就一起安裝)

二、下載對應的NGINX包

wget http://nginx.org/download/nginx-1.21.0.tar.gz

三、創建nginx用戶

useradd -r -s /sbin/nologin nginx

四、解壓nginx到/data/下

tar xf /root/nginx-1.21.0.tar.gz -C /data/

(路徑自定義)

五、進入解壓的nginx目錄中

cd /data/nginx-1.21.0/

六、編譯安裝

復制代碼
./configure --prefix=/apps/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module
復制代碼

計划安裝的路徑在/apps/

七、開始編譯

make -j 8 && make install

-j 8 表示CPU八核,可以按照實際CPU核數定義,越多越快

八、為了方便啟動可以創建軟鏈接或者修改PATH變量

ln -s /apps/nginx/sbin/nginx /usr/sbin/

九、開啟nginx服務

nginx

十、測試訪問

[09:34:18 root@localhost nginx-1.21.0]#curl 192.168.1.7
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

十一、設置為開機自啟動

  1、修改centos7自帶的開機自啟動文件中

vim  /etc/rc.d/rc.local

  2、添加NGINX的路徑

/usr/sbin/nginx

  3、這個文件默認沒有執行權限,添加執行權限

chmod +x /etc/rc.d/rc.local

十二、NGINX 的其他命令點擊此處查看

 注釋:執行./configure 會檢查當前環境是否滿足編譯要求,檢查當前的環境,並且生成makefile,這個Makefile就是編譯的時候使用的,make install 把生成的模塊拷貝到相應的目錄。

 


免責聲明!

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



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