Linux CentOS 6.x 開發配置文檔 - Nginx

1,安裝準備:
    a,yum -y install pcre-devel(If appear: ./configure: error: the HTTP rewrite module requires the PCRE library.)
    b,yum -y install openssl openssl-devel(If appear: ./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.)
    c,yum -y install libssl-dev(If appear: ./configure: error: the HTTP gzip module requires the zlib library.)
    d,yum -y install gcc-c++libtool: unrecognized option `-DHAVE_CONFIG_H'/compile: Try `libtool --help' for more information.)

2,先安裝 pcre
    a,下載:wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
    b,解壓:tar zxvf pcre-8.33.tar.gz
    c,進入:cd pcre-8.33
    d,配置:./configure
    e,編譯:make
    f,安裝:make install

3,安裝 Nginx
    a,下載:wget http://nginx.org/download/nginx-1.4.1.tar.gz
    b,解壓:tar zxvf nginx-1.4.1.tar.gz
    c,進入:cd nginx-1.4.1
    d,配置:./configure
    e,編譯:make
    f,安裝:make install

4,啓動 Nginx:/usr/local/nginx/sbin/nginx

5,驗證 Nginx 是否安裝正確:/usr/local/nginx/sbin/nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

6,關閉 Nginx:/usr/local/nginx/sbin/nginx -s stop

7,將 Nginx 作爲系統服務啓動:
    a,編輯:gedit /etc/rc.local
    b,添加:/usr/local/nginx/sbin/nginx

8,整合 Tomcat
    a,修改精簡版的 nginx.conf
        worker_processes 8; #官方的建議是:與CPU的內核數相等,實際情況下開4個或8個就可以了。
        events {
            worker_connections 1024;
        }
        http {
            include mime.types;
            default_type application/octet-stream;
            sendfile on;
            keepalive_timeout 65;
            include gzip.conf;
            upstream www.abc.com {
                server www.abc.com:8080;
            }
            server {
                listen 80;
                server_name localhost;
                log_format access '$remote_addr - $remote_user [$time_local] $request '
                '"$status" $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for"';
                access_log off;
                location / {
                    root html;
                    index index.html index.htm;
                    proxy_pass http://www.abc.com;
                    include proxy.conf;
                }
                error_page 500 502 503 504 /50x.html;
                location = /50x.html {
                root html;
            }
        }
    }

b,創建:gzip.conf,內容如下:
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_types text/plain text/css application/x-javascript;
output_buffers 1 32k;
postpone_output 1460;

c,創建:proxy.conf,內容如下:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #後端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP
client_max_body_size 10m; #允許客戶端請求的最大的單個文件字節數
client_body_buffer_size 128k; #緩衝區代理緩衝用戶端請求的最大字節數 可以理解爲先保存到本地再傳給用戶
proxy_connect_timeout 300; #跟後端服務器連接的超時時間_發起握手等候響應超時時間
proxy_send_timeout 300; #後端服務器數據回傳時間_就是在規定時間之內後端服務器必須傳完所有的數據
proxy_read_timeout 300; #連接成功後_等候後端服務器響應時間_其實已經進入後端的排隊之中等候處理
proxy_buffer_size 4k; #代理請求緩存區_這個緩存區間會保存用戶的頭信息以供Nginx進行規則處理_一般只要能保存下頭信息即可
proxy_buffers 4 32k; #同上 告訴Nginx保存單個用的幾個Buffer 最大用多大空間
proxy_busy_buffers_size 64k; #如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2
proxy_temp_file_write_size 64k; #proxy緩存臨時文件的大小


9,Nginx 升級到 Tengine:
(Tengine是由淘寶網發起的Web服務器開源項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了很多高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶網,天貓商城等得到了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平臺。)
1,下載:wget -c http://tengine.taobao.org/download/tengine-1.4.3.tar.gz
2,tar -zxvf tengine-1.4.3.tar.gz
3,cd tengine-1.4.3
4,./configure --prefix=/usr/local/nginx --without-http_autoindex_module --without-http_geo_module --without-http_map_module --without-http_browser_module --with-http_stub_status_module --with-http_realip_module --with-pcre=/root/pcre-8.32(這裏先下載並解壓pcre
5,make
6,make install
7,cp -r objs/nginx /usr/local/nginx/sbin/nginx
8,驗證一下:/usr/local/nginx/sbin/nginx -t
9,重啓服務(最好重啓機器):service nginx restart
10,檢查版本:/usr/local/nginx/sbin/nginx -V,第一行應該會出現:Tengine version: Tengine/1.4.3 (nginx/1.2.5)  ...


10,問題:
    1,因頻繁重啓,自己把自己的端口占用了,會出現:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use),解決方法:killall -9 nginx #殺掉nginx 進程
發佈了32 篇原創文章 · 獲贊 2 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章