CentOS 71編譯安裝nginx
文章轉自:https://typecodes.com/web/centos7compilenginx.html
如果編譯出錯檢視:https://typecodes.com/web/solvenginxcompileerror.html
1 依賴函式庫配置,編譯並安裝Nginx1.9.0
先建立一個名為nginx且沒有登入權限的使用者和一個名為nginx的使用者群組,然後安裝nginx所需的依賴函式庫和依賴包,最後透過.configure安裝的詳細設定。另外,補錄一個pcre的tar包備份位址:https://dn-vfhky.qbox.me/libs/nginx/pcre-8.36.tar.gz,以及一個zlib的tar包備份位址:https://dn -vfhky.qbox.me/libs/nginx/zlib-1.2.8.tar.gz。
#######新nginx使用者和nginx群組
[root@typecodes ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx
####### yum安裝nginx必須的依賴函式庫
[root@typecodes ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed
#Ngin###.90Ngin##.90Ngin#.的tar包,然後解壓縮到伺服器上
[root@typecodes ~]# wget -c http://nginx.org/download/nginx-1.9.0.tar.gz
[root@typecodes ~]# tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0
#######下載pcre的tar包並解壓縮,以便支援Nginx的Rewrite功能
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/php/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz
#######下載zlib的tar包並解壓縮,以便支援Nginx的Gzip壓縮功能
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/nginx/zlib-1.2.8.tar.gz
[root@ typecodes nginx-1.9.0]# tar -zxf zlib-1.2.8.tar.gz
#######新建Nginx1.9.0安裝時所需要的目錄
[root@typecodes nginx-1.9.0]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[root@typecodes tmp]# mkdir -p /var/run/nginx && cd ~/nginx -1.9.0
準備工作做好後,就開始正式設定Nginx-1.9.0的安裝明細了。注意,在使用下面這條configure參數配置時,一定要先把反斜線「」後面新增的註解文字去掉! ! !
[root@typecodes nginx-1.9.0]# ./configure
--prefix=/usr/share/nginx [Nginx的sbin目錄]
--conf-path=/etc/nginx/nginx.conf [Nginx的設定檔]
--error-log-path=/var/log/nginx/error.log [Nginx的錯誤日誌-
-- -log-path=/var/log/nginx/access.log [Nginx的存取日誌]
--pid-path=/var/run/nginx/nginx.pid [Nginx的進程ID]
--lock-path [Nginx的進程ID]
--lock-path =/var/lock/nginx.lock
--user=nginx [Nginx所屬使用者使用者 ]
--with-http_ssl_module [Nginx的ssl模組]
--with-http_spdy_module [Nginx的Google spdy模組]
--with-http_dav_module
--with-http_flv_module
--with-http_realip_module
--with-http_addition_module
--with-http_xslt_N--module _o_with--o--o--o--o--o--o--o--o--o--mod
--with-http_secure_link_module
--with-http_gzip_static_module .36 [pcre的安裝目錄]
--with-zlib=zlib-1.2.8 [pcre的安裝目錄]
--with-debug
--with-mail
--with-mail_ssl_module
--http-client-body-temp-path=/var/tmp/nginx/client_body
--http-proxy-temp-path=/var/tmp/nginx/proxy
--http-fastcgi-temp-path =/var/tmp/nginx/fastcgi
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
-- with-stream [Nginx1.9.0具中的stream模組]
--with-ld-opt="-Wl,-E" 選擇 即可
可能遇到問題:./configure: error: perl module ExtUtils::Embed is required
問題描述:缺少這個模組,需要yum安裝以下即可
解決方法:yum install perl perl-devel perl-ExtUtils-Embed
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/ log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/ lock/nginx.lock --user=nginx
--group=nginx --with-http_ssl_module --with-http_spdy_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_//////////////////////////////////合本 -111111111111666 月_stub_sub; --with-http_random_index_module
--with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_perl_module --with-pcre=pcre-8.36 --with-zlib=zlib-1.2.8 --with-debug --with-file -aio --with-mail --with-mail_ssl_module --http-client-body-temp-path=/var/tmp/nginx/client_body
--http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp /nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-ld-opt="-Wl,-E"
配置過程大概需要5分鐘左右
2 設定完後,就可以直接編譯安裝了
最後,直接使用執行這條指令[root@typecodes nginx-1.9.0]# make && make install進行安裝即可。
[root@typecodes nginx-1.9.0]# make && make install
3 設定Nginx1.9.0,使之正常工作
成功安裝Nginx1.9.0後,我們需要進行一些配置,包括開機啟動、SSL/HTTPS服務等。其中,Nginx服務控制腳本nginx請見文章《Nginx服務啟動、停止和重啟等操作的SHELL腳本》。
https://typecodes.com/web/nginxserviceoptshell.html
#######上傳Nginx服務控制腳本nginx,並賦予執行權限,刪除安裝包,新增Nginx服務到開機啟動
這一步驟可能會出現沒有nginx服務腳本,自行下載一個,或把下面的複製,然後檔案名稱為nginx
#檔案開始
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemin
#
# : - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/ng/ .conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
/config. /network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(name $name $name $name $ /usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $tfile
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
}
} configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVALe;
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
} &1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0$1 rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrehtry-restart)
rh_status
;; "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
#檔案結束
[root@typecodes ~]# mv ~/nginx / etc/init.d/nginx && chmod +x /etc/init.d/nginx
如果/etc/init.d/nginx存在,不要覆蓋,直接執行 chmod +x /etc/init.d/nginx
[root @typecodes ~]# rm -rf nginx-1.9.0*
[root@typecodes ~]# chkconfig --add nginx
[root@typecodes ~]# chkconfig nginx on
#######測試配置是否正常正常
root@typecodes ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is #新建Nginx進程日誌nginx.pid目錄,並啟動服務
加上這個mkdir就能夠兼容伺服器重啟這種情況了
[root@typecodes ~]# mkdir -p /var/run/nginx/
[root@typecodes ~]# service nginx start
以上就介紹了CentOS 71編譯安裝nginx,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位於 "NAMES" 列中)。

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

Docker 容器啟動步驟:拉取容器鏡像:運行 "docker pull [鏡像名稱]"。創建容器:使用 "docker create [選項] [鏡像名稱] [命令和參數]"。啟動容器:執行 "docker start [容器名稱或 ID]"。檢查容器狀態:通過 "docker ps" 驗證容器是否正在運行。

在雲服務器上配置 Nginx 域名的方法:創建 A 記錄,指向雲服務器的公共 IP 地址。在 Nginx 配置文件中添加虛擬主機塊,指定偵聽端口、域名和網站根目錄。重啟 Nginx 以應用更改。訪問域名測試配置。其他注意事項:安裝 SSL 證書啟用 HTTPS、確保防火牆允許 80 端口流量、等待 DNS 解析生效。

在 Docker 中創建容器: 1. 拉取鏡像: docker pull [鏡像名] 2. 創建容器: docker run [選項] [鏡像名] [命令] 3. 啟動容器: docker start [容器名]

可以查詢 Nginx 版本的方法有:使用 nginx -v 命令;查看 nginx.conf 文件中的 version 指令;打開 Nginx 錯誤頁,查看頁面的標題。

啟動 Nginx 服務器需要按照不同操作系統採取不同的步驟:Linux/Unix 系統:安裝 Nginx 軟件包(例如使用 apt-get 或 yum)。使用 systemctl 啟動 Nginx 服務(例如 sudo systemctl start nginx)。 Windows 系統:下載並安裝 Windows 二進製文件。使用 nginx.exe 可執行文件啟動 Nginx(例如 nginx.exe -c conf\nginx.conf)。無論使用哪種操作系統,您都可以通過訪問服務器 IP
