本文簡要介紹下如何在centos7下安裝nginx,以及nginx配置簡單說明。
一、安裝外掛程式
1.安裝gcc
yum install gcc-c++2.安裝pcre、pcre-devel
pcre是乙個perl庫,包括perl相容的正規表示式庫,nginx的http模組使用pcre來解析正規表示式,所以需要安裝pcre庫。命令如下:
yum install -y pcre pcre-devel3.安裝zlib
zlib庫提供了很多種壓縮和解壓縮方式,nginx使用zlib對http包的內容進行gzip。命令如下:
yum install -y zlib zlib-devel4.安裝openssl
openssl 是乙個強大的安全套接字層密碼庫,囊括主要的密碼演算法、常用的金鑰和證書封裝管理功能及 ssl 協議,並提供豐富的應用程式供測試或其它目的使用。nginx 不僅支援 http 協議,還支援 https,所以需要安裝 openssl 庫。命令如下:
yum install -y openssl openssl-devel二、安裝nginx
![](https://pic.w3help.cc/13c/e48080c5f1a63d9345a9ec626692b.jpeg)
3.使用nginx預設配置,命令如下:(當然也可以使用自定義配置,有興趣的小夥伴可以自行研究下)
./configure4.編譯安裝,命令如下:
make5.查詢安裝路徑,命令如下:make install
whereis nginx6.啟動、停止、重啟nginx
cd /usr/local/nginx/sbin/啟動
./nginx停止
./nginx -s quit -- 此方式停止步驟是待nginx程序處理任務完畢進行停止。重啟./nginx -s stop -- 此方式相當於先查出nginx程序id再使用kill命令強制殺掉程序。
./nginx -s quit當 nginx的配置檔案 nginx.conf 修改後,要想讓配置生效,使用-s reload 命令則不用先停止 nginx再啟動 nginx 即可將配置資訊在 nginx 中生效。命令如下:./nginx
./nginx -s reload檢視nginx程序。命令如下:
ps aux|grep nginx啟動成功後,可以在瀏覽器中看到以下頁面,至此,nginx安裝就完成了!
三、將nginx配置為系統服務
切換到/lib/systemd/system/目錄,建立nginx.service檔案。命令如下:
cd /lib/systemd/system/vim nginx.service檔案內容如下:
[unit]
description=nginx
after=network.target remote-fs.target nss-lookup.target
[service]
type=forking
execstart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
execreload=/usr/local/nginx/sbin/nginx -s reload
execstop=/usr/local/nginx/sbin/nginx -s quit
privatetmp=true
[install]
wantedby=multi-user.target
儲存檔案並退出,執行以下命令使nginx開機啟動
systemctl enable nginx.service配置檔案的解釋:
[unit]:服務的說明
description:服務描述
after:服務類別
[service]服務執行引數的設定
type=forking後台執行
execstart啟動命令
execreload重啟命令
execstop停止命令
privatetmp=true表示給服務分配獨立的臨時空間
注意:[service]的啟動、重啟、停止命令全部要求使用絕對路徑
[install]執行級別下服務安裝的相關設定,可設定為多使用者,即系統執行級別為3
最後,順便做個備註:
啟動nginx服務:
systemctl start nginx.service停止nginx服務:
systemctl stop nginx.service重啟nginx服務
systemctl restart nginx.service服務自動啟動
systemctl enable nginx.service服務禁止自動啟動
systemctl disable nginx.service檢視服務狀態
systemctl status nginx.service顯示所有已啟動的服務
systemctl list-units --type=service
CentOS 7下安裝配置FTP
ftp工具使用flashfxp,不推薦使用filezilla。yum install y vsftpdvi etc vsftpd vsftpd.conf anonymous enable no anonymous enable yes chroot local user yes 去掉前面的注釋 ch...
CentOS7下安裝配置vncserver
centos7下安裝配置 centos7下安裝配置 centos7安裝配置vncserver centos上vnc 啟動和關閉 常見問題彙總 vnc 連線不上,出現warning zhouziqi 1 is taken because of tmp x11 unix x1 vnc和主機之間共享剪下板...
CentOS7下安裝配置vncserver
首先試試伺服器裝了vnc沒 root wic rpm q tigervnc tigervnc server沒安裝的話會直接出現 package tigervnc is not installed package tigervnc server is not installed第一步,安裝vnc pa...