移植nginx到Windows上做開發環境的過程

來源:互聯網
上載者:User

轉自:http://bbs.chinaunix.net.fastcdn.com/viewthread.php?tid=1328536

 

我的電腦的記憶體不多,跑apache久了感覺很吃力,Nginx吃記憶體就像記事本吃那麼點,所以我自己編譯一個來做開發用

安裝前提:
安裝好cygwin,並安裝了gcc和g++  (安裝見http://www.xueler.com/docs/tool/åè£cygwin)
gzip 模組需要 zlib 庫
rewrite 模組需要 pcre 庫  
安裝nginx前先將pcre和zlib裝好
如果要使用ssl,還要openssl庫

  • 1、從nginx.net 下載源碼 nginx-0.7.24.tar.gz 存放到D:\linux\下
  • 2、使用cygwin把nginx安裝到d:/server/nginx

安裝命令

[Copy to clipboard] [ - ]

CODE:

cd /cygdrive/d/linux
tar zxvf nginx-0.7.24.tar.gz
cd nginx-0.7.24
./configure --prefix=/cygdrive/d/server/nginx --with-cc-opt="-D FD_SETSIZE=2048"
make && make install

如果不加–with-cc-opt=”-D FD_SETSIZE=2048”的話,你裝好nginx後運行會出現

  2008/01/12 16:34:56 [emerg] 2496#0: the maximum number of files supported by select() is 64的錯誤提示,這表示FD_SETSIZE的值比nginx設定檔中worker_connections指令所指定的值,你可以把nginx.conf裡的worker_connections選項改小一些,比如44,加了–with-cc-opt=”-DFD_SETSIZE=2048”後就不會碰到這問題

  • 3、從cygwin的bin目錄中把 cygcrypt-0.dll,cygpcre-0.dll,cygwin1.dll,cygz.dll拷貝到D:\server\nginx\sbin中

用cygwin編譯的nginx要獨立於cygwin啟動並執行時候需要這幾個擴充

到這裡就安裝完成了,下面來配置。
php和MySQL什麼裝這裡就不說了,我用的php解壓在D:\server\php
如果沒有裝php和mysql,nginx這樣的安裝與配置照樣能跑靜態檔案

  • 4、配置nginx+php+MySQL

我要開啟一個cgi進程來監聽處理php指令碼(在windows下開發開啟一個cgi進程已經能解決問題了)
我要啟動nginx,MySQL,讓nginx把對指令碼的請求轉寄給php-cgi處理
我還要方便的關閉php-cgi、nginx和MySQL

開啟在d:/server/nginx/conf/nginx.conf
這個設定檔裡給我們建立了一個預設的虛擬機器主機localhost,主目錄在d:/server/nginx/html/
找到 index  index.html index.htm;
改成 index  index.html index.htm index.php;
添加了nginx支援預設的php首頁
把內容類別似下面幾行配置的內容前的注釋去掉並改成

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  D:/server/nginx/html$fastcgi_script_name;
    include        fastcgi_params;
}

  • 5/製作nginx啟動關閉指令碼

在d:/server/nginx下建立start.bat和stop.bat
內容分別為:
d:/server/nginx/start.bat

[Copy to clipboard] [ - ]

CODE:

@echo off
echo php-cgi 正在啟動 ...
start /b D:\server\php\php-cgi.exe -b 127.0.0.1:9000 -c d:\server\php\php.ini
echo php-cgi 啟動完成 ...

echo nginx 正在啟動 ...
d:/server/nginx/sbin/nginx.exe
echo nginx 啟動完成 ...

net start mysql
echo 啟動完成

d:/server/nginx/stop.bat

[Copy to clipboard] [ - ]

CODE:

@echo off
echo php-cgi 正在關閉 ...
tskill php-cgi
echo php-cgi 關閉完成

echo nginx 正在關閉 ...
tskill nginx
echo nginx 關閉完成

net stop mysql
echo 關閉MySQL完成

開啟d:/server/nginx/start.bat和d:/server/nginx/stop.bat就可以分別啟動和關閉nginx+php+mysql(cgi)了

儘管是編譯安裝nginx,但是nginx代碼不是很多,編譯安裝完成所需時間比安裝Dreamweaver CS4要快多了
因為使用的是cygwin環境來把unix軟體編譯到window下運行,所以這裡有個問題是:我們只能在D:/server/nginx內建立虛擬機器主機目錄,在D:/server/nginx之外將無法讀取到裡面的web文檔檔案
把 configure改成

[Copy to clipboard] [ - ]

CODE:

./configure --prefix=/cygdrive --http-fastcgi-temp-path=d/server/fastcgi_temp --http-proxy-temp-path=d/server/proxy_temp --http-client-body-temp-path=d/server/client_body_temp --http-log-path=d/server/logs/access.log --error-log-path=d/server/logs/error.log --pid-path=d/server/logs/nginx.pid --sbin-path=d/server/sbin/nginx --conf-path=d/server/conf/nginx.conf --with-cc-opt="-D FD_SETSIZE=2048"

可以讓nginx讀到nginx prefix以外的分區,但分區名中不能帶: 並且只能用/,不能用\
比如把root設定到e:\web要寫成 root     e/web

下載我編譯和配置好的nginx0.7.24,編譯後的檔案很小,裡面占空間的是安裝流程檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.