qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Linux上搭建nginx,及簡單配置

           在上家公司都是運維安裝nginx,到新公司后代碼開發完成部署測試服務器要求自己裝nginx,研究了好久安裝好之后,到正式上線還要自己安裝,索性把安裝步驟自己記載下來(好大一部分都是在網站找的)。
            一,安裝
            1.選定源碼目錄
            可以是任何目錄,本文選定的是/usr/local/src
            cd/usr/local/src
            2.安裝PCRE庫
            ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下載最新的PCRE源碼包,使用下面命令下載編譯和安裝PCRE包:
          cd/usr/local/src
          wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
          tar-zxvfpcre-8.21.tar.gz
          cdpcre-8.21
          ./configure
          make
          makeinstall
            3.安裝zlib庫
            http://zlib.net/zlib-1.2.8.tar.gz下載最新的zlib源碼包,使用下面命令下載編譯和安裝zlib包:
          cd/usr/local/src
          wgethttp://zlib.net/zlib-1.2.8.tar.gz
          tar-zxvfzlib-1.2.8.tar.gz
          cdzlib-1.2.8
          ./configure
          make
          makeinstall
            4.安裝ssl(某些vps默認沒裝ssl)
            cd/usr/local/src
            wgethttp://www.openssl.org/source/openssl-1.0.1c.tar.gz
            tar-zxvfopenssl-1.0.1c.tar.gz
            5.安裝nginx
            Nginx一般有兩個版本,分別是穩定版和開發版,您可以根據您的目的來選擇這兩個版本的其中一個,下面是把Nginx安裝到/usr/local/nginx目錄下的詳細步驟:
          cd/usr/local/src
          wgethttp://nginx.org/download/nginx-1.4.2.tar.gz
          tar-zxvfnginx-1.4.2.tar.gz
          cdnginx-1.4.2
          ./configure--sbin-path=/usr/local/nginx/nginx\
          --conf-path=/usr/local/nginx/nginx.conf\
          --pid-path=/usr/local/nginx/nginx.pid\
          --with-http_ssl_module\
          --with-pcre=/usr/local/src/pcre-8.21\
          --with-zlib=/usr/local/src/zlib-1.2.8\
          --with-openssl=/usr/local/src/openssl-1.0.1c
          make
          makeinstall
          --with-pcre=/usr/src/pcre-8.21指的是pcre-8.21的源碼路徑。
          --with-zlib=/usr/src/zlib-1.2.7指的是zlib-1.2.7的源碼路徑。
            安裝成功后/usr/local/nginx目錄下如下
          fastcgi.confkoi-winnginx.conf.default
          fastcgi.conf.defaultlogsscgi_params
          fastcgi_paramsmime.typesscgi_params.default
          fastcgi_params.defaultmime.types.defaultuwsgi_params
          htmlnginxuwsgi_params.default
          koi-utfnginx.confwin-utf
            6.啟動
            確保系統的80端口沒被其他程序占用,運行/usr/local/nginx/nginx命令來啟動Nginx,
            netstat-ano|grep80
            如果查不到結果后執行,有結果則忽略此步驟(ubuntu下必須用sudo啟動,不然只能在前臺運行)
            sudo/usr/local/nginx/nginx
            打開瀏覽器訪問此機器的IP,如果瀏覽器出現Welcometonginx!則表示Nginx已經安裝并運行成功。
            二,簡單配置(nginx后掛resin或者tomcat)
            (標紅部分為自己新加的配置)
            注:只是簡單的配置
          http{
          upstreammgame-crm{
          server10.10.0.103:9080;
          server10.10.0.104:9080;
          }
          includemime.types;
          default_typeapplication/octet-stream;
          #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
          #'$status$body_bytes_sent"$http_referer"'
          #'"$http_user_agent""$http_x_forwarded_for"';
          #access_loglogs/access.logmain;
          sendfileon;
          #tcp_nopushon;
          #keepalive_timeout0;
          keepalive_timeout65;
          #gzipon;
          server{
          listen80;
          server_namelocalhost;
          #charsetkoi8-r;
          #access_loglogs/host.access.logmain;
          location/{
          roothtml;
          indexindex.htmlindex.htm;
          proxy_passhttp://mgame-crm;
          proxy_redirectoff;
          proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
          proxy_set_headerX-Real-IP$remote_addr;
          proxy_set_headerHost$http_host;
          access_logoff;
          }
          #error_page404/404.html;
          #redirectservererrorpagestothestaticpage/50x.html
          #
          error_page500502503504/50x.html;
          location=/50x.html{
          roothtml;
          }
          #proxythePHPscriptstoApachelisteningon127.0.0.1:80
          #
          #location~\.php${
          #proxy_passhttp://127.0.0.1;
          #}
          #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
          #
          #location~\.php${
          #roothtml;
          #fastcgi_pass127.0.0.1:9000;

          posted on 2014-07-15 10:33 順其自然EVO 閱讀(236) 評論(0)  編輯  收藏 所屬分類: linux

          <2014年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 杭州市| 冀州市| 都江堰市| 富顺县| 四会市| 五河县| 蓝山县| 巴彦淖尔市| 益阳市| 新晃| 绥芬河市| 德钦县| 台东县| 繁昌县| 巨野县| 资溪县| 封丘县| 上林县| 兴安县| 周口市| 崇阳县| 界首市| 扎囊县| 黄平县| 陆河县| 苏州市| 吴旗县| 洛宁县| 四子王旗| 兴海县| 道孚县| 惠东县| 大宁县| 江北区| 许昌市| 周至县| 凌海市| 平原县| 天等县| 曲麻莱县| 涿鹿县|