日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

linux安装nginx源码,CentOS7源码编译安装Nginx

發(fā)布時(shí)間:2025/7/14 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux安装nginx源码,CentOS7源码编译安装Nginx 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、安裝步驟

1、下載 nginx 源碼包 官網(wǎng)$?wget?http://nginx.org/download/nginx-1.16.0.tar.gz

2、解壓 nginx 壓縮包$?tar?-zxvf?nginx-1.16.0.tar.gz

3、創(chuàng)建 www 用戶 (已存在可以跳過)$?groupadd?www

$?useradd?-g?www?-s?/sbin/nologin?-M?www

4、運(yùn)行 configure 文件檢測程序$?cd?nginx-1.16.0

$?./configure?--prefix=/usr/local/nginx?--user=www?--group=www

checking?for?OS

+?Linux?3.10.0-957.12.2.el7.x86_64?x86_64

checking?for?C?compiler?...?not?found

./configure:?error:?C?compiler?cc?is?not?found

#?此處是因?yàn)闆]有?gcc?和?gcc-c++?依賴包,由于我是?centos?可以直接通過yum進(jìn)行安裝

$?yum?-y?install?gcc?gcc-c++

...?此處省略安裝步奏

#?再次執(zhí)行上面的?configure?步驟

$?./configure?--prefix=/usr/local/nginx?--user=www?--group=www

...?此處省略一部分

./configure:?error:?the?HTTP?rewrite?module?requires?the?PCRE?library.

You?can?either?disable?the?module?by?using?--without-http_rewrite_module

option,?or?install?the?PCRE?library?into?the?system,?or?build?the?PCRE?library

statically?from?the?source?with?nginx?by?using?--with-pcre=?option.

#?這次根據(jù)提示是因?yàn)闆]有?PCRE?庫?,執(zhí)行?yum?安裝?pcre-devel即可

$?yum?-y?install?pcre-devel

...?此處省略一部分

Running?transaction

正在安裝????:?pcre-devel-8.32-17.el7.x86_64???????????????????????????????1/1

驗(yàn)證中??????:?pcre-devel-8.32-17.el7.x86_64???????????????????????????????1/1

已安裝:

pcre-devel.x86_64?0:8.32-17.el7

完畢!

#?再次執(zhí)行?configure?步驟

$?./configure?--prefix=/usr/local/nginx?--user=www?--group=www

...?此處省略一部分

./configure:?error:?the?HTTP?gzip?module?requires?the?zlib?library.

You?can?either?disable?the?module?by?using?--without-http_gzip_module

option,?or?install?the?zlib?library?into?the?system,?or?build?the?zlib?library

statically?from?the?source?with?nginx?by?using?--with-zlib=?option.

#?這此根據(jù)提示是因?yàn)闆]有?zlib?庫?,執(zhí)行?yum?安裝?zlib?和?zlib-devel?即可

$?yum?-y?install?zlib?zlib-devel

...?此處省略一部分

Running?transaction

正在安裝????:?zlib-devel-1.2.7-18.el7.x86_64??????????????????????????1/1

驗(yàn)證中??????:?zlib-devel-1.2.7-18.el7.x86_64??????????????????????????????1/1

已安裝:

zlib-devel.x86_64?0:1.2.7-18.el7

完畢!

#?再次執(zhí)行?configure?步驟

$?./configure?--prefix=/usr/local/nginx?--user=www?--group=www

...?此處省略一部分

Configuration?summary

+?using?system?PCRE?library

+?OpenSSL?library?is?not?used

+?using?system?zlib?library

nginx?path?prefix:?"/usr/local/nginx"

nginx?binary?file:?"/usr/local/nginx/sbin/nginx"

nginx?modules?path:?"/usr/local/nginx/modules"

nginx?configuration?prefix:?"/usr/local/nginx/conf"

nginx?configuration?file:?"/usr/local/nginx/conf/nginx.conf"

nginx?pid?file:?"/usr/local/nginx/logs/nginx.pid"

nginx?error?log?file:?"/usr/local/nginx/logs/error.log"

nginx?http?access?log?file:?"/usr/local/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"

#?總算通過了下面進(jìn)行編譯和安裝

$?make?&&?make?install

#?檢測是否安裝成功

$?/usr/local/nginx/sbin/nginx?-t

nginx:?the?configuration?file?/usr/local/nginx/conf/nginx.conf?syntax?is?ok

nginx:?configuration?file?/usr/local/nginx/conf/nginx.conf?test?is?successful

#?辛苦總算沒有白費(fèi),成功了.

5、啟動 nginx 服務(wù)$?/usr/local/nginx/sbin/nginx

#?啟動了一個(gè)nginx服務(wù),然我測試下是否啟動成功

$?lsof?-i:80

COMMAND???PID???USER???FD???TYPE?DEVICE?SIZE/OFF?NODE?NAME

nginx???17440???root????6u??IPv4??35217??????0t0??TCP?*:http?(LISTEN)

nginx???17441?nobody????6u??IPv4??35217??????0t0??TCP?*:http?(LISTEN)

#?完成。

#?PS:如果?lsof?沒有這個(gè)操作可以使用?yum?-y?install?lsof?安裝

6、配置防火墻80端口$?firewall-cmd?--zone=public?--add-port=80/tcp?--permanent

$?systemctl?restart?firewalld

二、安裝總結(jié)#?下載、解壓?源碼包

$?wget?http://nginx.org/download/nginx-1.16.0.tar.gz

$?tar?-zxvf?nginx-1.16.0.tar.gz

#?創(chuàng)建?www?用戶?(已存在可以跳過)

$?groupadd?www

$?useradd?-g?www?-s?/sbin/nologin?-M?www

#?安裝?前置服務(wù)

$?yum?-y?install?gcc?gcc-c++?pcre-devel?zlib?zlib-devel

#?檢測安裝環(huán)境

$?./configure?--prefix=/usr/local/nginx?--user=www?--group=www

#?編譯?和?安裝

$?make?&&?make?install

#?啟動服務(wù)

$?/usr/local/nginx/sbin/nginx

#?打開防火墻

$?firewall-cmd?--zone=public?--add-port=80/tcp?--permanent

$?systemctl?restart?firewalld

三、操作命令#?停止

[1]

$?pkill?-9?nginx

[2]

$?nginx?-s?stop

#?檢查配置是否正確

$?nginx?-t

#?重啟

$?nginx?-s?reload

四、配置開機(jī)自啟

由于我是 CentOS 7 ,我打算用 systemctl 作為我的管理工具,下面是我的操作步驟。

還有一個(gè)原因是因?yàn)槲遗渲?nginx 啟動腳本總是報(bào)錯(cuò),我懶得去弄官網(wǎng)給的那個(gè)腳本了。$?vim?/lib/systemd/system/nginx.service

#?輸入以下代碼,并且保存

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx?reload

ExecStop=/usr/local/nginx/sbin/nginx?quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

$?systemctl?start?nginx.service

Failed?to?execute?operation:?Access?denied

#?這里報(bào)了一個(gè)錯(cuò)誤,提示我沒有權(quán)限

$?setenforce?0?#?臨時(shí)關(guān)閉?selinux?,如果想長久關(guān)閉請自行搜索

$?systemctl?start?nginx

#?沒有報(bào)錯(cuò),測試一下

$?lsof?-i:80

COMMAND??PID?USER???FD???TYPE?DEVICE?SIZE/OFF?NODE?NAME

nginx???1398?root????6u??IPv4??19609??????0t0??TCP?*:http?(LISTEN)

nginx???1399??www????6u??IPv4??19609??????0t0??TCP?*:http?(LISTEN)

#?成功,設(shè)置為開機(jī)自動啟動

$?systemctl?enable?nginx.service

本文來自投稿,不代表訪得立場,如若轉(zhuǎn)載,請注明出處:http://www.found5.com//view/1073.html

總結(jié)

以上是生活随笔為你收集整理的linux安装nginx源码,CentOS7源码编译安装Nginx的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。