柚子快報激活碼778899分享:linux Nginx源碼安裝
柚子快報激活碼778899分享:linux Nginx源碼安裝
Nginx源碼安裝1.25.4
目錄
步驟一:1.準備工作關閉防火墻檢查防火墻
步驟二:1.下載最新版本的nginx源代碼包進入該目錄下載最新版本的nginx源代碼包2.解壓源代碼包
步驟三:1.安裝Nginx的依賴包2.執(zhí)行configure腳本生成編譯配置文件Makefile3.執(zhí)行make命令編譯源代碼4.執(zhí)行make install 安裝軟件5.測試nginx
步驟三:1.停掉nginx2.創(chuàng)建nginx.service文件
后續(xù)步驟:停掉nginx創(chuàng)建一個名為nginx的組賬戶創(chuàng)建一個屬于該組的同名用戶,不允許該用戶登錄和創(chuàng)建主目錄
步驟一:
1.準備工作
關閉防火墻
systemctl stop firewalld
檢查防火墻
systemctl status firewalld
步驟二:
1.下載最新版本的nginx源代碼包
首先創(chuàng)建一個目錄用于存放nginx源代碼包
mkdir nginx
進入該目錄
cd nginx
下載最新版本的nginx源代碼包
wget https://nginx.org/download/nginx-1.25.4.tar.gz
//應該大于1.9.9的都行
2.解壓源代碼包
tar -xzvf nginx-1.25.4.tar.gz
跑完一大串后
進入該目錄
cd nginx-1.25.4
步驟三:
1.安裝Nginx的依賴包
C和C++編譯環(huán)境
yum install gcc gcc-c++ -y
PCRE庫
yum install pcre pcre-devel -y
OpenSSL庫
yum install openssl openssl-devel -y
2.執(zhí)行configure腳本生成編譯配置文件Makefile
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
–prefix=/usr/local/nginx 指定安裝路徑
–with-http_stub_status_module 表示支持Nginx狀態(tài)查詢
–with-http_ssl_module 表示啟用SSL支持
–with-http_gzip_static_module 表示啟用GZIP功能
3.執(zhí)行make命令編譯源代碼
先下make
yum install make -y
執(zhí)行make
make
4.執(zhí)行make install 安裝軟件
make install
至此完成nginx的編譯安裝
5.測試nginx
如果安裝了Apache服務先停止
systemctl stop http.service
打開nginx
根據(jù)上述設置,nginx安裝在/usr/local/nginx 目錄中
/usr/local/nginx/sbin/nginx
打開瀏覽器輸入ip
重新加載配置
/usr/local/nginx/sbin/nginx -s reload
重啟
/usr/local/nginx/sbin/nginx -s reopen
停止
/usr/local/nginx/sbin/nginx -s stop
退出
/usr/local/nginx/sbin/nginx -s quit
步驟三:
編寫systemd單元文件管理nginx服務
通常在/usr/lib/systemd/system或/etc/systemd/system/目錄下創(chuàng)建nginx.service文本文件
1.停掉nginx
/usr/local/nginx/sbin/nginx -s stop
2.創(chuàng)建nginx.service文件
vim /etc/systemd/system/nginx.service
添加以下內(nèi)容
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存退出
要讓systemd重新識別此單元文件,執(zhí)行
systemctl daemon-reload
啟動nginx
systemctl start nginx
隨機啟動
systemctl enable nginx
后續(xù)步驟:
出于安全考慮,nginx不應以root身份運行,而應以普通用戶和組的身份運行
停掉nginx
systemctl stop nginx
創(chuàng)建一個名為nginx的組賬戶
groupadd nginx
創(chuàng)建一個屬于該組的同名用戶,不允許該用戶登錄和創(chuàng)建主目錄
useradd -s /sbin/nologin -g nginx -M nginx
如何使用創(chuàng)建的用戶啟動nginx
根據(jù)上述設置nginx安裝位置為/usr/local/nginx 目錄,所以配置文件在/usr/local/nginx/conf目錄下
vim /usr/local/nginx/conf/nginx.conf
找到user指令,并設置為之前創(chuàng)建的用戶和組
user nginx nginx;
保存退出
systemctl start nginx
檢查Nginx進程的用戶
ps -ef | grep nginx
柚子快報激活碼778899分享:linux Nginx源碼安裝
參考鏈接
本文內(nèi)容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉載請注明,如有侵權,聯(lián)系刪除。