CentOS安裝Nginx

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   使用   ar   

1. 下載:http://nginx.org/en/download.html

2. 安裝依賴:yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel

3. wget http://nginx.org/download/nginx-1.4.4.tar.gz

4.  tar zxf nginx-1.4.4.tar.gz

 

5. cd nginx-1.4.4

6. ./configure

 

  --prefix=<path> - Nginx安裝路徑。如果沒有指定,預設為 /usr/local/nginx。

  --sbin-path=<path> - Nginx可執行檔安裝路徑。只能安裝時指定,如果沒有指定,預設為<prefix>/sbin/nginx

  --conf-path=<path> - 在沒有給定-c選項下預設的nginx.conf的路徑。如果沒有指定,預設為<prefix>/conf/nginx.conf。

  --pid-path=<path> - 在nginx.conf中沒有指定pid指令的情況下,預設的nginx.pid的路徑。如果沒有指定,預設為 <prefix>/logs/nginx.pid。

  --lock-path=<path> - nginx.lock檔案的路徑。

  --error-log-path=<path> - 在nginx.conf中沒有指定error_log指令的情況下,預設的錯誤記錄檔的路徑。如果沒有指定,預設為 <prefix>/logs/error.log。

  --http-log-path=<path> - 在nginx.conf中沒有指定access_log指令的情況下,預設的訪問日誌的路徑。如果沒有指定,預設為 <prefix>/logs/access.log。

  --user=<user> - 在nginx.conf中沒有指定user指令的情況下,預設的nginx使用的使用者。如果沒有指定,預設為 nobody。

  --group=<group> - 在nginx.conf中沒有指定user指令的情況下,預設的nginx使用的組。如果沒有指定,預設為 nobody。

  --builddir=DIR - 指定編譯的目錄

  --with-rtsig_module - 啟用 rtsig 模組最後安裝 

7. make && make install

8.  設定成系統開機服務

  在 /etc/init.d/ 目錄下建立 nginx 檔案 內容如下:

 

#!/bin/bash    # nginx Startup script for the Nginx HTTP Server# this script create it by gcec at 2009.10.22.# it is v.0.0.1 version.# if you find any errors on this scripts,please contact gcec cyz.# and send mail to support at gcec dot cc.## chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it‘s not for everyone.# processname: nginx# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0prog="nginx" # Source function library.. /etc/rc.d/init.d/functions # Source networking configuration.. /etc/sysconfig/network # Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions.start() { if [ -e $nginx_pid ];then   echo "nginx already running...."   exit 1fi   echo -n $"Starting $prog: "   daemon $nginxd -c ${nginx_config}   RETVAL=$?   echo   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx   return $RETVAL} # Stop nginx daemons functions.stop() {        echo -n $"Stopping $prog: "        killproc $nginxd        RETVAL=$?        echo        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid} # reload nginx service functions.reload() {     echo -n $"Reloading $prog: "    #kill -HUP `cat ${nginx_pid}`    killproc $nginxd -HUP    RETVAL=$?    echo}# See how we were called.case "$1" instart)        start        ;;stop)        stop        ;;reload)        reload        ;;restart)        stop        start        ;;status)        status $prog        RETVAL=$?        ;;*)        echo $"Usage: $prog {start|stop|restart|reload|status|help}"        exit 1esacexit $RETVAL 

 

 9. 添加到服務:

  chmod 0777 /etc/init.d/nginx

  chkconfig --add nginx

  chkconfig --level 345 nginx on

  chkconfig --list nginx

  啟動

  service nginx start

  停止

  service nginx stop  

  

  

CentOS安裝Nginx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.