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