mkdir -p /home/softs &&
cd /home/softs
wget
二、編譯安裝nginx
# 安裝依賴包
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 解壓
tar -zxvf nginx-1.18.0.tar.gz
# 進入目錄
cd nginx-1.18.0
# 使用預設配置
./configure
# 編譯 安裝
make
make
install
# 查詢安裝目錄
whereis nginx
三、配置啟動指令碼# 建立init.d指令碼
vi /etc/init.d/nginx
/etc/init.d/nginx 內容:
#! /bin/sh
# chkconfig: 2345 55 25
# description: startup script for nginx webserver on debian. place in /etc/init.d and
# distro. for centos/redhat run: 'chkconfig --add nginx'
### begin init info
# provides: nginx
# required-start: $all
# required-stop: $all
# default-start: 2 3 4 5
# default-stop: 0 1 6
# short-description: starts the nginx web server
# description: starts nginx using start-stop-daemon
### end init info
# author: licess
# website:
nginx_bin=
'/usr/local/nginx/sbin/nginx'
config=
'/usr/local/nginx/conf/nginx.conf'
case
"$1"
in start)
echo -n "starting nginx... "
pid=
$(ps -ef |
grep
"$nginx_bin"
|grep -v grep
|awk'')
if["$pid"
!=""];
then
echo
"nginx (pid $pid) already running."
exit 1
fi$nginx_bin -c $configif[
"$?"
!= 0 ]
;then
echo
" failed"
exit 1
else
echo
" done"fi;
; stop)
echo -n "stoping nginx... "
pid=
$(ps -ef |
grep
"$nginx_bin"
|grep -v grep
|awk'')
if["$pid"=""
];then
echo
"nginx is not running."
exit 1
fi$nginx_bin -s stop
if["$?"
!= 0 ]
;then
echo
" failed. use force-quit"
$0 force-quit
else
echo
" done"fi;
; status)
pid=
$(ps -ef |
grep
"$nginx_bin"
|grep -v grep
|awk'')
if["$pid"
!=""];
then
echo
"nginx (pid $pid) is running..."
else
echo
"nginx is stopped."
exit 0
fi;;
force-quit|kill)
echo -n "terminating nginx... "
pid=
$(ps -ef |
grep
"$nginx_bin"
|grep -v grep
|awk'')
if["$pid"=""
];then
echo
"nginx is is stopped."
exit 1
fikill
$pidif[
"$?"
!= 0 ]
;then
echo
" failed"
exit 1
else
echo
" done"fi;
; restart)
$0 stop
sleep 1
$0 start
;; reload)
echo -n "reload nginx... "
pid=
$(ps -ef |
grep
"$nginx_bin"
|grep -v grep
|awk'')
if["$pid"
!=""];
then
$nginx_bin -s reload
echo
" done"
else
echo
"nginx is not running, can't reload."
exit 1
fi;;
configtest)
echo -n "test nginx configure files... "
$nginx_bin -t
;; *)
echo
"usage: $0 "
exit 1
;;esac
# 修改許可權
chmod +x /etc/init.d/nginx
# 啟動
/etc/init.d/nginx start
# 設定開機自動啟動
chkconfig nginx on
# 檢視執行狀態
/etc/init.d/nginx status
四、配置防火牆# 啟動服務
systemctl start firewalld.service
# 放行80埠
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 過載配置
firewall-cmd --reload
# 檢視配置
firewall-cmd --list-all
# 開啟自動啟動
systemctl enable firewalld.service
五、訪問測試
nginx安裝 Centos7安裝nginx
在安裝nginx前首先要確認系統中安裝了gcc pcre devel zlib devel openssl devel。yum y install gcc pcre devel zlib devel openssl openssl devel 解壓 tar zxvf nginx 1.9.9.tar....
Linux學習 CentOS 7 安裝Nginx
pcre 作用是讓 nginx 支援 rewrite 功能。root bogon src cd usr local src root bogon src wget 2 解壓安裝包 root bogon src tar zxvf pcre 8.35.tar.gz3 進入安裝包目錄 root bogon...
centos7安裝Nginx 使用nginx記錄
1 安裝各種依賴 gcc安裝,nginx原始碼編譯需要 yum install gcc c pcre pcre devel 安裝,nginx 的 http 模組使用 pcre 來解析正規表示式 yum install y pcre pcre devel zlib安裝,nginx 使用zlib對htt...