Nginx安裝

nginx安裝環境

nginxC語言開發,建議在linux上運行,本教程使用Centos6.5做爲安裝環境。linux

  • gcc

    安裝nginx須要先將官網下載的源碼進行編譯,編譯依賴gcc環境,若是沒有gcc環境,須要安裝nginx

    gccyum install gcc-c++ c++

  • PCRE

    PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginxhttp模塊使用pcre來解析正則表達式,因此須要在linux上安裝pcre庫。正則表達式

    yum install -y pcre pcre-devel算法

    注:pcre-devel是使用pcre開發的一個二次開發庫。nginx也須要此庫。安全

  • zlib

    zlib庫提供了不少種壓縮和解壓縮的方式,nginx使用zlibhttp包的內容進行gzip,因此須要在linux上安裝zlib庫。服務器

    yum install -y zlib zlib-devel測試

  • openssl

    OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用。ui

    nginx不只支持http協議,還支持https(即在ssl協議上傳輸http),因此須要在linux安裝openssl庫。spa

    yum install -y openssl openssl-devel

編譯安裝

  將nginx-1.8.0.tar.gz拷貝至linux服務器。

  解壓:

    tar -zxvf nginx-1.8.0.tar.gz

    cd nginx-1.8.0

  • 配置makefile 參數設置以下:

    ./configure \

    --prefix=/usr/local/nginx \

    --pid-path=/var/run/nginx/nginx.pid \

    --lock-path=/var/lock/nginx.lock \

    --error-log-path=/var/log/nginx/error.log \

    --http-log-path=/var/log/nginx/access.log \

    --with-http_gzip_static_module \

    --http-client-body-temp-path=/var/temp/nginx/client \

    --http-proxy-temp-path=/var/temp/nginx/proxy \

    --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

    --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

    --http-scgi-temp-path=/var/temp/nginx/scgi

      注意:上邊將臨時文件目錄指定爲/var/temp/nginx,須要在/var下建立tempnginx目錄(mkdir /var/temp/nginx -p)

  • 編譯安裝

    make

    make  install (會安裝到usr/local/nginx)

  • 啓動nginx

  cd /usr/local/nginx/sbin/

  ./nginx

  注意:執行./nginx啓動nginx,這裏能夠-c指定加載的nginx配置文件,以下:

  ./nginx -c /usr/local/nginx/conf/nginx.conf

  若是不指定-cnginx在啓動時默認加載conf/nginx.conf文件,此文件的地址也能夠在編譯安裝nginx時指定./configure的參數(--conf-path= 指向配置文件(nginx.conf))

  •  中止nginx

    方式1,快速中止:

    cd /usr/local/nginx/sbin

    ./nginx -s stop

    此方式至關於先查出nginx進程id再使用kill命令強制殺掉進程。

    方式2,完整中止(建議使用)

    cd /usr/local/nginx/sbin

    ./nginx -s quit

    此方式中止步驟是待nginx進程處理任務完畢進行中止。

  • 重啓nginx

    方式1,先中止再啓動(建議使用):

      對nginx進行重啓至關於先中止nginx再啓動nginx,即先執行中止命令再執行啓動命令。

      以下:

      ./nginx -s quit

      ./nginx

    方式2,從新加載配置文件:

      當nginx的配置文件nginx.conf修改後,要想讓配置生效須要重啓nginx,使用-s reload不用先中止nginx再啓動nginx便可將配置信息在nginx中生效,以下:

      ./nginx -s reload

輸入ip119.23.50.194 便可訪問nginx (nginx默認80端口)

相關文章
相關標籤/搜索