本篇內(nèi)容主要講解“Centos6下部署Nginx的方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Centos6下部署Nginx的方法”吧!
10余年建站經(jīng)驗(yàn), 成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)客戶的見證與正確選擇。創(chuàng)新互聯(lián)建站提供完善的營銷型網(wǎng)頁建站明細(xì)報(bào)價(jià)表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。
Nignx:tengine-2.2.2.tar.gz
1.解壓
tar zxvf tengine-2.2.2.tar.gz
2.配置檢查
進(jìn)入解壓后的目錄 ./configure
錯(cuò)誤1:
[root@localhost tengine-2.2.2]# ./configure
checking for OS
+ Linux 2.6.32-642.el6.x86_64 x86_64
checking for C compiler ... not found
解決:
yum -y install gcc gcc-c++ autoconf automake make
錯(cuò)誤2:
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
解決:
yum install pcre-devel
錯(cuò)誤3:
checking for PCRE JIT support ... not found
checking for OpenSSL library ... not found
解決:
yum -y install openssl openssl-devel
再次檢查./configure是否報(bào)錯(cuò)
3.安裝
make && make install 安裝完成 安裝目錄為/usr/local/nginx
找到 /usr/local/nginx/sbin/nginx -V 查看所有加載的模塊
/usr/local/nginx/sbin/nginx start|stop|restart 啟動(dòng)和關(guān)閉ngix服務(wù)
訪問 http://ip地址
4.nignx命令參數(shù)
nginx -m 顯示所有加載的模塊
nginx -l 顯示所有可以使用的指令
nginx -t 檢查nginx的配置文件是否正確
nginx -s start 啟動(dòng)nginx
nginx -s reload 重啟nginx
nginx -s stop 停止nginx
5.開機(jī)啟動(dòng)nginx
第一步:nignx命令文件移動(dòng)到 /etc/init.d/目錄下
nginx命令文件內(nèi)容:
#!/bin/sh # # 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: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/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:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -n "$user" ]; then 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 fi } 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
第二步:賦權(quán)限chmod 775 nginx
第三步:添加到系統(tǒng)服務(wù) 設(shè)置開機(jī)啟動(dòng)
chkconfig --add nginx
chkconfig nginx on
第四步:
service nginx status 檢查狀態(tài)
service nginx stop 停止服務(wù)
service nginx start 啟動(dòng)服務(wù)
service nginx restart 啟動(dòng)服務(wù)
6.80端口永久開放
第一步:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
第二步:service iptables save
7.前后臺(tái)動(dòng)靜分離配置,/usr/local/nginx/conf/nginx.conf vi修改
location / {
root /var/www/xxx; --前端項(xiàng)目xxx丟到www目錄下
index index.html index.htm;
}
location ~/datav {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
proxy_pass http://127.0.0.1:8888;
}
8.重啟服務(wù)service nginx restart,使nginx新配置生效
到此,相信大家對(duì)“Centos6下部署Nginx的方法”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!