搜尋
首頁後端開發php教程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_degradation_module
--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教學有興趣的朋友有幫助。


陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
超越炒作:評估當今PHP的角色超越炒作:評估當今PHP的角色Apr 12, 2025 am 12:17 AM

PHP在現代編程中仍然是一個強大且廣泛使用的工具,尤其在web開發領域。 1)PHP易用且與數據庫集成無縫,是許多開發者的首選。 2)它支持動態內容生成和麵向對象編程,適合快速創建和維護網站。 3)PHP的性能可以通過緩存和優化數據庫查詢來提升,其廣泛的社區和豐富生態系統使其在當今技術棧中仍具重要地位。

PHP中的弱參考是什麼?什麼時候有用?PHP中的弱參考是什麼?什麼時候有用?Apr 12, 2025 am 12:13 AM

在PHP中,弱引用是通過WeakReference類實現的,不會阻止垃圾回收器回收對象。弱引用適用於緩存系統和事件監聽器等場景,需注意其不能保證對象存活,且垃圾回收可能延遲。

解釋PHP中的__ Invoke Magic方法。解釋PHP中的__ Invoke Magic方法。Apr 12, 2025 am 12:07 AM

\_\_invoke方法允許對象像函數一樣被調用。 1.定義\_\_invoke方法使對象可被調用。 2.使用$obj(...)語法時,PHP會執行\_\_invoke方法。 3.適用於日誌記錄和計算器等場景,提高代碼靈活性和可讀性。

解釋PHP 8.1中的纖維以進行並發。解釋PHP 8.1中的纖維以進行並發。Apr 12, 2025 am 12:05 AM

Fibers在PHP8.1中引入,提升了並發處理能力。 1)Fibers是一種輕量級的並發模型,類似於協程。 2)它們允許開發者手動控制任務的執行流,適合處理I/O密集型任務。 3)使用Fibers可以編寫更高效、響應性更強的代碼。

PHP社區:資源,支持和發展PHP社區:資源,支持和發展Apr 12, 2025 am 12:04 AM

PHP社區提供了豐富的資源和支持,幫助開發者成長。 1)資源包括官方文檔、教程、博客和開源項目如Laravel和Symfony。 2)支持可以通過StackOverflow、Reddit和Slack頻道獲得。 3)開發動態可以通過關注RFC了解。 4)融入社區可以通過積極參與、貢獻代碼和學習分享來實現。

PHP與Python:了解差異PHP與Python:了解差異Apr 11, 2025 am 12:15 AM

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

php:死亡還是簡單地適應?php:死亡還是簡單地適應?Apr 11, 2025 am 12:13 AM

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來:改編和創新PHP的未來:改編和創新Apr 11, 2025 am 12:01 AM

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具