qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 http://qaseven.github.io/

          Linux上搭建nginx,及簡單配置

           在上家公司都是運(yùn)維安裝nginx,到新公司后代碼開發(fā)完成部署測試服務(wù)器要求自己裝nginx,研究了好久安裝好之后,到正式上線還要自己安裝,索性把安裝步驟自己記載下來(好大一部分都是在網(wǎng)站找的)。
            一,安裝
            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默認(rèn)沒裝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一般有兩個(gè)版本,分別是穩(wěn)定版和開發(fā)版,您可以根據(jù)您的目的來選擇這兩個(gè)版本的其中一個(gè),下面是把Nginx安裝到/usr/local/nginx目錄下的詳細(xì)步驟:
          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.啟動(dòng)
            確保系統(tǒng)的80端口沒被其他程序占用,運(yùn)行/usr/local/nginx/nginx命令來啟動(dòng)Nginx,
            netstat-ano|grep80
            如果查不到結(jié)果后執(zhí)行,有結(jié)果則忽略此步驟(ubuntu下必須用sudo啟動(dòng),不然只能在前臺(tái)運(yùn)行)
            sudo/usr/local/nginx/nginx
            打開瀏覽器訪問此機(jī)器的IP,如果瀏覽器出現(xiàn)Welcometonginx!則表示Nginx已經(jīng)安裝并運(yùn)行成功。
            二,簡單配置(nginx后掛resin或者tomcat)
            (標(biāo)紅部分為自己新加的配置)
            注:只是簡單的配置
          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 閱讀(233) 評論(0)  編輯  收藏 所屬分類: linux

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 祁阳县| 林周县| 绥芬河市| 宣汉县| 新宁县| 五家渠市| 安义县| 晋城| 福建省| 太康县| 洛川县| 博客| 朝阳市| 台南市| 图木舒克市| 天台县| 平武县| 屏东县| 长顺县| 当阳市| 清丰县| 儋州市| 建瓯市| 兴隆县| 晋宁县| 栖霞市| 如皋市| 桑日县| 赣榆县| 安塞县| 遵化市| 澄迈县| 武威市| 济南市| 德钦县| 扶风县| 哈巴河县| 泽州县| 高邮市| 睢宁县| 尚志市|