Linux(CentOS)環(huán)境下安裝下載Nginx并配置
1、準(zhǔn)備工作
選首先安裝這幾個(gè)軟件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。
Nginx是C寫的,需要用GCC編譯;Nginx的Rewrite和HTTP模塊會(huì)用到PCRE;Nginx中的Gzip用到zlib;
用命令“# gcc”,查看gcc是否安裝;如果出現(xiàn)“gcc: no input files”信息,說(shuō)明已經(jīng)安裝好了。
否則,就需要用命令“# yum install gcc”,進(jìn)行安裝了!一路可能需要多次輸入y,進(jìn)行確認(rèn)。
安裝好后,可以再用命令“#gcc”測(cè)試,或者用命令“# gcc -v”查看其版本號(hào)。
同樣方法,用如下命令安裝PCRE,zlib,OpenSSL(其中devel,是develop開(kāi)發(fā)包的意思):
# yum install -y pcre pcre-devel # yum install -y zlib zlib-devel # yum install -y openssl openssl-devel
2、下載并安裝
創(chuàng)建目錄(nginx-src)并進(jìn)去;然后,從官方地址(http://nginx.org/)下載,解壓,配置,編譯,安裝:
# mkdir nginx-src && cd nginx-src # wget http://nginxorg/download/nginx-targz # tar xzf nginx-targz # cd nginx-3 # /configure # make # make install # whereis nginx nginx: /usr/local/nginx
默認(rèn)的安裝路徑為:/usr/local/nginx;跳轉(zhuǎn)到其目錄下sbin路徑下,便可以啟動(dòng)或停止它了。
# /nginx -h nginx version: nginx/3 Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginxconf) -g directives : set global directives out of configuration file
啟動(dòng):nginx
停止:nginx -s stop
3、添加到系統(tǒng)服務(wù)
使用命令“# vi /etc/init.d/nginx”,打開(kāi)編輯器,輸入如下內(nèi)容:
#!/bin/sh
# chkconfig: 2345 85 15
# Startup script for the nginx Web Server
# description: nginx is a World Wide Web server
# It is used to serve HTML files and CGI
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginxpid
# config: /usr/local/nginx/conf/nginxconf
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx deamon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/initd/$NAME
test -x $DAEMON || exit 0
d_start(){
$DAEMON || echo -n "already running"
}
d_stop(){
$DAEMON -s quit || echo -n "not running"
}
d_reload(){
$DAEMON -s reload || echo -n "can not reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo ""
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo ""
;;
reload)
echo -n "Reloading $DESC conf"
d_reload
echo "reload "
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 2
d_start
echo ""
;;
*)
echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
保存退出后,再使用下面的命令,使其可執(zhí)行;然后,添加配置并查看。
可用chkconfig修改其值,也可用ntsysv工具改變是否自啟動(dòng)。
# chmod +x /etc/initd/nginx # chkconfig --add nginx # chkconfig nginx on/off # chkconfig --list nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
linux實(shí)現(xiàn)除了某個(gè)文件或某個(gè)文件夾以外的全部刪除
下面小編就為大家?guī)?lái)一篇linux實(shí)現(xiàn)除了某個(gè)文件或某個(gè)文件夾以外的全部刪除。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
關(guān)于Read-only file system問(wèn)題的解決
這篇文章主要介紹了關(guān)于Read-only file system問(wèn)題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
阿里云云服務(wù)器遠(yuǎn)程連接管理Linux服務(wù)器圖文教程
這篇文章主要介紹了阿里云云服務(wù)器遠(yuǎn)程連接管理Linux服務(wù)器圖文教程,本文使用Putty客戶端軟件,并附軟件下載地址,需要的朋友可以參考下2014-09-09
Linux系統(tǒng)?Centos7.4手動(dòng)在線升級(jí)到Centos7.7
這篇文章主要介紹了Centos7.4手動(dòng)升級(jí)到Centos7.7,需要的朋友可以參考下2022-01-01
Linux系統(tǒng)crontab定時(shí)運(yùn)行shell腳本失敗的問(wèn)題及解決
這篇文章主要介紹了Linux系統(tǒng)crontab定時(shí)運(yùn)行shell腳本失敗的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
確保Linux VPS及服務(wù)器更加安全之Xshell設(shè)置密鑰登錄
這篇文章主要介紹了Xshell設(shè)置密鑰登錄確保Linux VPS及服務(wù)器更加安全,需要的朋友可以參考下2016-10-10
linux-centos7擴(kuò)展swap分區(qū)方式
這篇文章主要介紹了linux-centos7擴(kuò)展swap分區(qū)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08

