Linux-Centos7 下編譯安裝nginx (附nginx開機啟動指令碼)
1.安裝編譯所需環境:
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.下載原始碼包(這裡用的是nginx-1.14.0)
wget http://nginx.org/download/nginx-1.14.0.tar.gz
3.編譯安裝
---新增使用者和組
groupadd www
useradd -g www www
---解壓壓縮包,並cd進去
#tar -xvzf nginx-1.14.0.tar.gz #cd nginx-1.14.0/ #./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module #make && make install
---nginx模板粗略解釋
nginx大部分常用模組,編譯時./configure --help以--without開頭的都預設安裝。
--prefix=PATH : 指定nginx的安裝目錄。預設 /usr/local/nginx
--conf-path=PATH : 設定nginx.conf配置檔案的路徑。nginx允許使用不同的配置檔案啟動,通過命令列中的-c選項。預設為prefix/conf/nginx.conf
--user=name: 設定nginx工作程序的使用者。安裝完成後,可以隨時在nginx.conf配置檔案更改user指令。預設的使用者名稱是nobody。--group=name類似
--with-pcre : 設定PCRE庫的原始碼路徑,如果已通過yum方式安裝,使用--with-pcre自動找到庫檔案。使用--with-pcre=PATH時,需要從PCRE網站下載pcre庫的原始碼(版本4.4 - 8.30)並解壓,剩下的就交給Nginx的./configure和make來完成。perl正則表示式使用在location指令和 ngx_http_rewrite_module模組中。
--with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的原始碼解壓目錄。在預設就啟用的網路傳輸壓縮模組ngx_http_gzip_module時需要使用zlib 。
--with-http_ssl_module : 使用https協議模組。預設情況下,該模組沒有被構建。前提是openssl與openssl-devel已安裝
--with-http_stub_status_module : 用來監控 Nginx 的當前狀態
--with-http_realip_module : 通過這個模組允許我們改變客戶端請求頭中客戶端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意義在於能夠使得後臺伺服器記錄原始客戶端的IP地址
--add-module=PATH : 新增第三方外部模組,如nginx-sticky-module-ng或快取模組。每次新增新的模組都要重新編譯(Tengine可以在新加入module時無需重新編譯)
4.驗證是否安裝成功,並建立軟連線
#/usr/local/nginx/sbin/nginx -V //下方為輸出顯示結果 nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module #ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
5.啟動檢視web介面
#/usr/bin/nginx //啟動nginx
#lsof -i:80 //檢視埠
#curl localhost:80 //是否啟動,下方為顯示結果
[[email protected] nginx-1.14.0]# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
6.設定開機啟動指令碼
一:建立指令碼
# vim /etc/init.d/nginx
#!/bin/sh
# tiger
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 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/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
二:賦予指令碼可執行許可權
# chmod a+x /etc/init.d/nginx
三:將nginx服務加入chkconfig管理列表
# chkconfig --add /etc/init.d/nginx
# chkconfig nginx on
相關推薦
Linux-Centos7 下編譯安裝nginx (附nginx開機啟動指令碼)
1.安裝編譯所需環境: yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel 2.下載原始碼包(這裡用的是nginx-1.14.0) wget http://nginx.org/download/
Linux-Centos7 下編譯安裝nginx (附nginx開機啟動指令碼)
1.安裝編譯所需環境: yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel 2.下載原始碼包(這裡用的是nginx-1.14.0) wget http://nginx.org/
centos7下編譯安裝lnmp和nginx代理實驗
ket orm pass glib href status log nal listen 1、先安裝mysql cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux
詳解Centos7 下編譯安裝Nginx和yum搭建Nginx兩種方法
Nginx 在併發與負載能力方面確實優於 apache,大多數網站都採用基於Nginx 來搭建網站。 下面就來介紹Nginx的搭建 一 原始碼安裝nginx 首先先來安裝Nginx,但是本地的yum倉庫中只有apache,並沒有Nginx,這就需要手動安裝了。 Nginx 的下載官網是這個http
linux下編譯安裝php7(相容現有的php5.6版本)
1.首先去php官網下載一個php7版本原始碼包 http://php.net/downloads.php,我這下載的是php7.2.13版本. 2.使用ftp或者linux的rz命令將包上傳到linux下,開始進行編譯安裝. 3.解壓安裝包 # tar -zxvf
Linux環境下編譯安裝Mysql
mysql上一篇文章介紹了手工編譯安裝Apache,這篇文章將繼續之前的文章,介紹如何編譯安裝Mysql。 - 二、 編譯安裝Mycql 1. 首先解壓mysql文件到/opt目錄。 tar zxvf /opt/lamp/mysql-5.5.24.tar.gz -C /opt/ 2.確認安裝 gcc 、
Centos7.x 編譯安裝全功能的Nginx
centos7.x reg red types rds -cp yum 應用場景 ticket 說明 根據此文檔進行編譯安裝 Nginx,可以將Nginx默認的功能全部安裝上,讀者也可以自己的根據實際情況刪減需要編譯的模塊。 支持的特色功能如下: 支持 TLSv1.3
Centos7編譯安裝ffmpeg(兩個字形容“噁心”)以及迴圈播放本地視訊命令
迴圈播放本地視訊 ffmpeg -re -stream_loop -1 -i /root/rtmp/video/sss.mp4 -vcodec copy -acodec copy -f flv rtmp://0.0.0.0:1935/live/test1 /root/rtmp/vi
linux centos7下簡單安裝 7-zip
基於目前最新版本16.02 7-zip : 下載解壓命令 wget https://nchc.dl.sourceforge.net/project/p7zip/p7zip/16.02/p7zip_
linux(Centos)下編譯安裝gcc4.8.2
最近要用到c++ 11,所以沒辦法只得把那臺centos6.6的gcc4.4.7升級一下。 gcc編譯器已經出到5.1了,但是我對最新的版本並沒有特別大的興趣,更喜歡穩定性的版本。 gcc4.8.1 是第一個完全支援C++11 的編譯器,我這邊裝的是4.8.2.一、獲取
Linux編譯安裝ffmpeg(兩個字形容“噁心”)以及迴圈播放本地視訊命令
系統版本:Centos7 迴圈播放本地視訊 ffmpeg -re -stream_loop -1 -i /root/rtmp/video/sss.mp4 -vcodec copy -acodec copy -f flv rtmp://0.0.0.0:1935/l
CentOS7下redis安裝配置(yum)
預設埠為6379 預設配置檔案位置: /etc/redis.conf Redis預設不是以守護程序的方式執行,可以通過該配置項修改,使用yes啟用守護程序(daemonize no) 當Redis以守護程序方式執行時,Redis預設會把pid寫入/var/run/redis.pid檔案,可以通過pidfile
CentOS7下編譯安裝ffmpeg3.1.5
一、安裝依賴包 # yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-dev
Centos7下編譯安裝mariadb
一、安裝cacti新版的的時候yum安裝了mariadb資料庫,結果版本不符合要求,cacti要求版本在yum源上沒有配置,於是用編譯安裝的方法安裝mariadb-10.1.32二、安裝準備1、下載安裝包 從https://downloads.mariadb.org/下載ma
linux centos7下php7安裝redis擴充套件
下載php7的redis擴充套件git clone -b develop https://github.com/phpredis/phpredis.git$ cd phpredis# 進入 phpredis 目錄 $ /usr/local/php/bin/phpize
PyTorch1.0安裝教程(附三個測試示例)
Summary:Python1.0安裝教程 Author:Amusi Date:2018-12-20 github:https://github.com/amusi/PyTorch-From-Zero-To-One 知乎:https://www.zhihu
開發工具MySQL-MySQL5.7.20服務端圖文安裝教程(附:錯誤解決方案)
一、官網地址 https://www.mysql.com/downloads/ 二、安裝(windows安裝包安裝) 1.點選mysql-installer-community-5.7.20.msi安裝 2.點選點“接受”,Next 3.選“Server Only”,
學習體驗centos7 下根目錄擴容操作(步驟詳細!!!)
code number metadata memory 目錄擴容 目錄 internal 邏輯卷擴容 nts [root@testandy ~]# fdisk -l Disk /dev/sda: 53.7 GB, 53687091200 bytes,
ssh連線遠端主機執行指令碼的環境變數問題(編寫hadoop叢集啟動指令碼)
參考:https://blog.csdn.net/whitehack/article/details/51705889 如: 遠端主機執行指令碼報錯:(因為這種方式是non-interactive + non-login shell,不會去載入/etc/profile系統環境變數,可以配置使
linux環境手動編譯安裝Nginx實踐過程 附異常解決
ima 根據 目錄結構 key -a text 參數 文件中 修改 1、下載nginx源碼包並解壓 可在http://nginx.org/en/download.html下載.tar.gz的源碼包,如(nginx-1.4.7.tar.gz) 或者使用雲盤下載