A. 安裝nginx後,怎麼安裝/升級到tengine
/*
************************************
**Nginx平滑升級Tengine
************************************
*/
SSH登陸,執行如下的代碼
wget -c http://tengine.taobao.org/download/tengine-1.5.1.tar.gz //下載Tengine1.5.1版本
tar zxvf tengine-1.5.1.tar.gz //解壓到當前目錄
cd tengine-1.5.1 //進入到目錄
./configure //執行安裝腳本
make //編譯安裝
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old //備份nginx的配置文件,路徑參考你自己的
cp -r objs/nginx /usr/local/nginx/sbin/nginx //復制Tengine文件到nginx下
vi /usr/local/nginx/conf/nginx.conf //編輯nginx.conf,刪除如下代碼
location /status {
stub_status on;
access_log off;
}
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
//結束nginx進程
/usr/local/nginx/sbin/nginx -v //查看nginx版本號
返回帶有Tengine版本號等信息則升級成功!
/*
************************************
**卸載Tengine,換回Nginx
************************************
*/
rm -rf /usr/local/nginx/sbin/nginx //刪除Tengine配置文件
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old //恢復備份的nginx配置文件,路徑參考你自己的
/etc/init.d/nginx restart //重啟nginx
/usr/local/nginx/sbin/nginx -v //查看nginx版本號
返回帶有Nginx版本號則卸載成功
B. nginx編譯安裝服務啟動腳本在哪
在你編譯是 --prefix=指定的目錄下有一個bin目錄,裡面有一個nginx啟動腳本,如果沒有指定,默認在/usr/local/nginx下,即/usr/local/nginx/sbin/nginx
C. Nginx模塊怎麼調試
(1)修改nginx源代碼目錄下子目錄/auto/cc中的conf文件,將ngx_compile_opt="-c"改為ngx_compile_opt="-c -g"
(2)在編譯的時候加上debug選項,nginx的安裝腳本如下:
./configure --user=www --group=www --prefix=/export/lx/servers/nginx-debug --add-mole=../ngx_cache_purge-1.2 --with-debug --with-pcre --with-http_sub_mole --with-http_stub_status_mole --with-http_ssl_mole
make -j 18&& make -j 18 install
(3)修改安裝完畢之後生成的nginx配置文件:nginx.conf,加入
error_log /export/lx/servers/nginx_debug/logs/error.log debug;配置項
如果是做模塊開發,則需要將nginx設置為單進程模式才可以調試開發的模塊中的代碼
加入如下幾句配置項:
worker_processes 1;
master_process off; # 單進程模式
daemon off;
D. ubuntu怎麼安裝nginx
Nginx程序的穩定性來自於它採用了分階段的資源分配技術,使得CPU與內存佔用率會非常低,所以使用Nginx程序部署動態網站環境不僅十分的穩定、高效,而且消耗更少的系統資源,豐富的模塊功能也幾乎與Apache程序數量相同,現在已經完全的支持了proxy、rewrite、mod_fcgi、ssl、vhosts等常用模塊。而且還支持了熱部署技術,即能夠可以7*24不間斷提供服務,即便運行數月也無須重啟,而且還可以在不暫停服務的情況下直接對Nginx服務程序進行升級。
坦白來講,雖然Nginx程序的代碼質量非常高,代碼很規范,技術成熟,模塊擴展也很容易,但Nginx依然存在不少問題,比如Nginx是由俄羅斯人創建的,所以在資料文檔方面還並不完善,中文教材的質量更是魚龍混雜,但Nginx近年來增長勢頭迅猛,預測未來應該能夠在輕量級HTTP伺服器市場有不錯的未來。
安裝PCRE(Perl兼容的正則表達式庫,解壓與編譯過程已省略):
[root@linuxprobe ~]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/pcre
[root@linuxprobe src]# tar xzvf pcre-8.35.tar.gz
[root@linuxprobe src]# cd pcre-8.35
[root@linuxprobe pcre-8.35]# ./configure --prefix=/usr/local/pcre
[root@linuxprobe pcre-8.35]# make
[root@linuxprobe pcre-8.35]# make install
安裝openssl服務程序(解壓與編譯過程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/openssl
[root@linuxprobe src]# tar xzvf openssl-1.0.1h.tar.gz
[root@linuxprobe src]# cd openssl-1.0.1h
[root@linuxprobe openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@linuxprobe openssl-1.0.1h]# make
[root@linuxprobe openssl-1.0.1h]# make install
把openssl服務程序命令目錄添加到環境變數中(永久生效):
[root@linuxprobe pcre-8.35]# vim /etc/profile
//將配置文件最下面的參數追加參數為:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
[root@linuxprobe pcre-8.35]# source /etc/profile
安裝zlib數據壓縮函數庫(解壓與編譯過程已省略):
[root@linuxprobe pcre-8.35]# cd /usr/local/src
[root@linuxprobe src]# mkdir /usr/local/zlib
[root@linuxprobe src]# tar xzvf zlib-1.2.8.tar.gz
[root@linuxprobe src]# cd zlib-1.2.8
[root@linuxprobe zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@linuxprobe zlib-1.2.8]# make
[root@linuxprobe zlib-1.2.8]# make install
創建用於執行nginx服務的用戶:
[root@linuxprobe zlib-1.2.8]# cd ..
[root@linuxprobe src]# useradd www -s /sbin/nologin
安裝nginx服務程序(openssl,zlib,pcre要寫成源碼解壓路徑!!!):
[root@linuxprobe src]# tar xzvf nginx-1.6.0.tar.gz
[root@linuxprobe src]# cd nginx-1.6.0/
[root@linuxprobe nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_mole --user=www --group=www --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
[root@linuxprobe nginx-1.6.0]# make
[root@linuxprobe nginx-1.6.0]# make install
創建nginx程序腳本(將下面的參數直接復制進去即可):
[root@linuxprobe nginx-1.6.0]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# 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: /usr/local/nginx/conf/nginx.conf
# 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
[root@linuxprobe nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
重啟nginx服務程序並添加到開機啟動項:
[root@linuxprobe nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Restarting nginx (via systemctl): [ OK ]
[root@linuxprobe nginx-1.6.0]# chkconfig nginx on
此時可以通過訪問IP來判斷nginx服務是否順利運行
我們一般通過部署Linux+Nginx+MYSQL+PHP這四種開源軟體,搭建一個免費、高效、擴展性強、資源消耗低的LNMP動態網站架構。關於這塊的安裝使用你可以看下http://www.linuxprobe.com/chapter-20.html#2022_Nginx
E. Nginx怎麼安裝配置
1、在線安裝 Ubuntu版的 sudo apt-get install nginx;CentOS 版 sudo yum install nginx;
2、源碼安裝 下載地址:http://nginx.org/download/
所有的配置文件都在/etc/nginx下,並且每個虛擬主機已經安排在了/etc/nginx/sites-available下
啟動程序文件在/usr/sbin/nginx
日誌放在了/var/log/nginx中,分別是access.log和error.log
並已經在/etc/init.d/下創建了啟動腳本nginx
默認的虛擬主機的目錄設置在了/usr/share/nginx/www
在線安裝的啟動過程$sudo /etc/init.d/nginx start
F. centos7怎麼編譯安裝nginx
安裝環境為:最小化安裝的centos7,關閉seliunx。
最小化安裝centos:
關閉selinux
sed –i 『s/SELINUX=enforcing/SELINUX=disabled/g』 /etc/selinux/config
開始安裝nginx1.7.8
創建群組
groupadd www
創建一個用戶,不允許登陸和不創主目錄
useradd -s /sbin/nologin -g www -M www
#下載最新版nginx
wget -C http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxvf nginx-1.7.8.tar.gz
#編譯基本能運行的nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
make install
如果有錯誤提示:
./configure: error: C compiler cc is not found
解決方法:
yum install gcc gcc-c++
如果有錯誤提示:
./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre=<path> option.
解決方法:
yum install pcre-devel
如果有錯誤提示:
./configure: error: SSL moles require the OpenSSL library.
You can either do not enable the moles, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using –with-openssl=<path> option.
解決方法:
yum install openssl-devel
以上錯誤提示依次解決後:再一次的運行
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_mole --with-http_ssl_mole --with-http_gzip_static_mole
make
meke install
編譯參數解釋:
#指定運行許可權的用戶
--user=www
#指定運行的許可權用戶組
--group=www
#指定安裝路徑
--prefix=/usr/local/nginx
#支持nginx狀態查詢
--with-http_stub_status_mole
#開啟ssl支持
--with-http_ssl_mole
#開啟GZIP功能
--with-http_gzip_static_mole
因此要順利的通過nginx編譯安裝必須安裝的依賴關系有:
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel
2、在 centos7 中為nginx的啟動、重啟、重載配置添加腳本
nginx直接啟動的方法:
/usr/local/nginx/sbin/nginx
但是不是很方便,因此使用下面的腳本來控制nginx的啟動關閉重載更加合理一些。
編輯文件:vim /usr/lib/systemd/system/nginx.service 添加下面的腳本,注意路徑 !
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl的一些使用方法:
systemctl is-enabled servicename.service #查詢服務是否開機啟動
systemctl enable xxx.service #開機運行服務
systemctl disable xxx.service #取消開機運行
systemctl start xxx.service #啟動服務
systemctl stop xxx.service #停止服務
systemctl restart xxx.service #重啟服務
systemctl reload xxx.service #重新載入服務配置文件
systemctl status xxx.service #查詢服務運行狀態
systemctl --failed #顯示啟動失敗的服務
因此,添加上面腳本後,centos7 中操作nginx的方法有
systemctl is-enabled nginx.service #查詢nginx是否開機啟動
systemctl enable nginx.service #開機運行nginx
systemctl disable nginx.service #取消開機運行nginx
systemctl start nginx.service #啟動nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重啟nginx
systemctl reload nginx.service #重新載入nginx配置文件
systemctl status nginx.service #查詢nginx運行狀態
systemctl --failed #顯示啟動失敗的服務
G. ubuntu怎麼安裝nginx+mysql+php
1、更新 1 sudo apt-get update 2、安裝nginx 1 sudo apt-get intsall nginx Ubuntu安裝之後的文件結構大致為: * 所有的配置文件都在/etc/nginx下,並且每個虛擬主機已經安排在了/etc/nginx/sites-available下 *程序文件在/usr/sbin/nginx * 日誌放在了/var/log/nginx中 *並已經在/etc/init.d/下創建了啟動腳本nginx * 默認的虛擬主機的目錄設置在了/var/www/nginx-default 下面可以啟動nginx來看看效果(請確保80埠沒有其他服務在使用): 1 sudo /etc/init.d/nginx start #或者簡單的 1 service nginx start 然後打開瀏覽器,查看localhost/ 看看是否看到了」Welcome to nginx!」 如果看到了,說明安裝成功. 當然,基本上,這塊兒都不會出問題. 如果運行不成功,可以先 1 sudo killall apache2 殺掉apache進程 3、安裝php sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl 4、安裝spawn-fcgi 為什麼要安裝spawn-fcgi呢,它用來控制php-cgi進程,以防止進程崩潰或是單進程的效率太低. 網上很多人都說要使用spawn-fcgi必須得安裝lighttpd,實際上不必要,可以直接安裝spawn-fcgi 運行: 1 sudo apt-get install spawn-fcgi 5、配置 接下來就是最讓人頭疼的配置. 配置Nginx和spawn-fcgi配合運行 (1).在/etc/nginx/fastcgi_params 文件最後,加入一行,可以用 1 sudo vi /etc/nginx/fastcgi_params 加入此行: 1 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; (2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位於/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo選項,修改為: 1 cgi.fix_pathinfo=1; 這樣php-cgi方能正常使用SCRIPT_FILENAME這個變數. (3).打開/etc/nginx/sites-available/default文件在 1 2 3 server { listen 80; server_name localhost; 下面添加web根目錄的絕對地址,這里是使用的是nginx的默認地址 1 root /var/www/nginx-default 即root和server_name同級這段即相當於apache的默認目錄 如果沒有這個的話,容易在執行php 文件的時候,會提示」No input file specified」. 我就曾在此繞了好大個圈子才發現問題.然後修改 1 2 3 4 5 6 #location ~ .php$ { #fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #includefastcgi_params; #} 修改成 1 2 3 4 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include /etc/nginx/fastcgi_params; #包含fastcgi的參數文件地址 6、開始fast_cgi進程 1、sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 7、設置開機啟動fastcgi進程並啟動 1 sudo vi /etc/rc.local 添加下一行 1 /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 如果打開php文件出現:No input file specified請檢查php.ini的配置中 1 cgi.fix_pathinfo=1 1 doc_root= 還有,每個虛機要根據自己不同的虛機設置不同的目錄,要保證這個路徑正確. 檢查/etc/nginx/sites-available下的配置文件中,server內包含 root 及地址 而非location內的root 啟動 1 fast-cgisudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid 參數含義如下 * -f 指定調用FastCGI的進程的執行程序位置,根據系統上所裝的PHP的情況具體設置 * -a 綁定到地址addr * -p 綁定到埠port * -s 綁定到unix socket的路徑path * -C 指定產生的FastCGI的進程數,默認為5(僅用於PHP) * -P指定產生的進程的PID文件路徑 * -u和-g FastCGI使用什麼身份(-u 用戶 -g 用戶組)運行,Ubuntu下可以使用www-data,其他的根據情況配置,如nobody、apache等現在可以在web根目錄下放個探針或php文件測試一下了 8、安裝mysql 1 sudo apt-get install mysql-server mysql-client 中間會提示輸入Root用戶密碼,依次輸入即可. 啟動MySQL 1 sudo /etc/init.d/mysql start 測試mysql服務是否正常: 運行 1 mysql -uroot -p 輸入mysql密碼 1 show databases; 如果看到下面的內容 Database information_schema mysql 則mysql已正確安裝了. 至此,ubuntu下的nginx+php+mysql就安裝完成了.