系統(tǒng)版本
1细疚、安裝nginx服務(wù)器需要的相關(guān)依賴
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre-devel
gcc gcc-c++編譯環(huán)境
gzip 模塊需要 zlib 庫
rewrite 模塊需要 pcre 庫
ssl 功能需要openssl庫
2寇损、下載nginx源碼包。
wget http://nginx.org/download/nginx-1.19.2.tar.gz
3揪垄、解壓nginx源碼包
tar xvf nginx-1.19.2.tar.gz
4皇拣、進(jìn)入安裝目錄
cd nginx-1.19.2
5严蓖、使用./configure,生成配置文件makefile氧急,并配置nginx的安裝路徑
./configure --prefix=/usr/local/nginx
6颗胡、編譯安裝nginx
make && make install
7、因?yàn)榫幾g需要配置才能使用systemctl啟動吩坝,所以我們先通過安裝路徑啟動一下我們的nginx
/usr/local/nginx/sbin/nginx 啟動服務(wù)
/usr/local/nginx/sbin/nginx -s top 停止服務(wù)
/usr/local/nginx/sbin/nginx -s reload 重啟服務(wù)
8毒姨、通過netstat -tnlp 或者 ps aux|grep nginx查看服務(wù)是否啟動。
9钉寝、測試(注意如果你用的是VMWare虛擬機(jī)的話弧呐,需要關(guān)閉防火墻,才能在我們的物理機(jī)訪問nginx)
10嵌纲、給nginx配置通過systemctl啟動,打開vim /usr/lib/systemd/system/nginx.service文件俘枫,輸入以下內(nèi)容:
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
這個時候會出現(xiàn)如下圖所示的報(bào)錯
解決方法如下:
[root@localhost ~]# mkdir /etc/systemd/system/nginx.service.d
[root@localhost ~]# printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
[root@localhost ~]# systemctl deamon-reload 加載新的unit 配置文件
11、如下圖所示就是配置成功了,可以設(shè)置一下開機(jī)自啟動systemctl enable nginx.service