您好,登錄后才能下訂單哦!
本篇內容主要講解“Centos6下部署Nginx的方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Centos6下部署Nginx的方法”吧!
Nignx:tengine-2.2.2.tar.gz
1.解壓
tar zxvf tengine-2.2.2.tar.gz
2.配置檢查
進入解壓后的目錄 ./configure
錯誤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
錯誤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
錯誤3:
checking for PCRE JIT support ... not found
checking for OpenSSL library ... not found
解決:
yum -y install openssl openssl-devel
再次檢查./configure是否報錯
3.安裝
make && make install 安裝完成 安裝目錄為/usr/local/nginx
找到 /usr/local/nginx/sbin/nginx -V 查看所有加載的模塊
/usr/local/nginx/sbin/nginx start|stop|restart 啟動和關閉ngix服務
訪問 http://ip地址
4.nignx命令參數
nginx -m 顯示所有加載的模塊
nginx -l 顯示所有可以使用的指令
nginx -t 檢查nginx的配置文件是否正確
nginx -s start 啟動nginx
nginx -s reload 重啟nginx
nginx -s stop 停止nginx
5.開機啟動nginx
第一步:nignx命令文件移動到 /etc/init.d/目錄下
nginx命令文件內容:
#!/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
第二步:賦權限chmod 775 nginx
第三步:添加到系統服務 設置開機啟動
chkconfig --add nginx
chkconfig nginx on
第四步:
service nginx status 檢查狀態
service nginx stop 停止服務
service nginx start 啟動服務
service nginx restart 啟動服務
6.80端口永久開放
第一步:/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
第二步:service iptables save
7.前后臺動靜分離配置,/usr/local/nginx/conf/nginx.conf vi修改
location / {
root /var/www/xxx; --前端項目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.重啟服務service nginx restart,使nginx新配置生效
到此,相信大家對“Centos6下部署Nginx的方法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。