CentOS 編譯安裝 nginx
修改 yum 源地址為 阿里云
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
升級(jí)內(nèi)核和軟件
yum -y update
安裝常用軟件和依賴
yum -y install gcc gcc-c++ make cmake zlib zlib-devel openssl openssl-devel pcre-devel vim net-tools man wget tar
創(chuàng)建用戶用戶組
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
下載并編譯安裝
下載
wget https://nginx.org/download/nginx-1.24.0.tar.gz
解壓
tar -zxvf nginx-1.24.0.tar.gz
進(jìn)入nginx源代碼目錄
cd nginx-1.24.0
預(yù)編譯
./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-http_stub_status_module --with-http_ssl_module \
--with-http_realip_module --with-http_gzip_static_module \
--with-file-aio --with-http_realip_module
驗(yàn)證 是否 成功
echo $?
編譯
make -j4
驗(yàn)證 是否 成功
echo $?
安裝
make -j4 install
驗(yàn)證 是否 成功
echo $?
ls 以下為驗(yàn)證程序步驟可忽略
/usr/local/nginx/sbin/nginx -v
/usr/local/nginx/sbin/nginx -t
# 啟動(dòng)nginx
/usr/local/nginx/sbin/nginx
# 重新載入配置文件
/usr/local/nginx/sbin/nginx -s reload
# 快速關(guān)閉 Nginx
/usr/local/nginx/sbin/nginx -s stop
# 關(guān)閉Nginx
/usr/local/nginx/sbin/nginx -s quit
編寫啟動(dòng)腳本
cd /usr/lib/systemd/system/
vim nginx.service
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPost=/bin/sleep 0.1
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
# systemctl start|stop|reload|restart|status nginx.service
# 重新加載服務(wù)文件
systemctl daemon-reload
# 啟動(dòng) nginx 服務(wù)
systemctl start nginx.service
# 開機(jī)自啟:
systemctl enable nginx.service
# 關(guān)閉開機(jī)自啟:
systemctl disable nginx.service
防火墻開放端口
–zone 作用域
–add-port=80/tcp 添加端口
–permanent 永久生效
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
瀏覽器訪問測(cè)試
http://服務(wù)器IP地址文章來源:http://www.zghlxwxcb.cn/news/detail-716840.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-716840.html
到了這里,關(guān)于CentOS 編譯安裝 nginx的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!