1、首先在官網下載Nginx 發布版的源碼,
Nginx 官網下載的地址是 :http://www.nginx.org/en/download.html
因為Nginx官網支持SVN,可以簡單方便的使用svn下載的是Nginx 1.3.0 版源碼編譯,命令如下:
svn checkout svn://svn.nginx.org/nginx/tags/release-1.3.0
2、configure信息的配置說明
簡單瀏覽下載的源碼后,可以發現和編譯相關的信息文件在auto目錄下,其中configure也在這個目錄下。用vi打開configure,可以發現它應該放在源碼的頂級目錄下,移動configure 命令如下:
mv configure ../
再回到頂級目錄,運行configure 即可生成Makefile 文件。這里需要注意的是,根據自己的需求設置configure的參數來生成Makefile文件。例如,如果你需要Nginx 支持https協議,那么configure的命令需要加上參數 --with-http_ssl_module ,當然你的linux系統中也要安裝相應的OPENSSL庫,具體命令: ./configure --with-http_ssl_module。細心的我們可以看到,沒加這個參數生成Makefile文件時,顯示的信息中有:+ OpenSSL library is not used ,而添加參數 --with-http_ssl_module 后,則是:using system OpenSSL library。其他模塊的安裝類是。在此,也可以知道Nginx 1.3 版本中可能要用的的支持庫有
PCRE library
OpenSSL library
OpenSSL library
OpenSSL library
zlib library
補充說明下的是默認下Nginx相關文件安裝路徑的信息是:
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
也可以通過configure 加入相應的參數修改這些信息。
3、在根據自己需求配置完configure文件,生成Makefile文件后,就可以執行make命令,即可完成Nginx源代碼的編譯。同時用命令 make install 進行安裝部署。若是ubuntu系統由於需要對系統目錄進行操作需要sudo(其他操作若出現權限不夠 Permission denied時都需要)。在默認安裝路徑的情況下,啟動Nginx的命令如下:/usr/local/nginx/sbin/nginx。打開瀏覽器輸入localhost 出現:
Welcome to nginx!
的歡迎頁面,至此Nginx源碼編譯安裝完成。關閉nginx命令:/usr/local/nginx/sbin/nginx -s stop
4、附上網上找到的一些configure 參數:
#Nginx安裝路徑。如果沒有指定,默認為 /usr/local/nginx。 --prefix=PATH #Nginx可執行文件安裝路徑。只能安裝時指定,如果沒有指定,默認為PATH/sbin/nginx。 --sbin-path=PATH #在沒有給定-c選項下默認的nginx.conf的路徑。如果沒有指定,默認為PATH/conf/nginx.conf。 --conf-path=PATH #在nginx.conf中沒有指定pid指令的情況下,默認的nginx.pid的路徑。如果沒有指定,默認為 PATH/logs/nginx.pid。 --pid-path=PATH #nginx.lock文件的路徑。 --lock-path=PATH #在nginx.conf中沒有指定error_log指令的情況下,默認的錯誤日志的路徑。如果沒有指定,默認為 PATH/logs/error.log。 --error-log-path=PATH #在nginx.conf中沒有指定access_log指令的情況下,默認的訪問日志的路徑。如果沒有指定,默認為 PATH/logs/access.log。 --http-log-path=PATH #在nginx.conf中沒有指定user指令的情況下,默認的nginx使用的用戶。如果沒有指定,默認為 nobody。 --user=USER #在nginx.conf中沒有指定user指令的情況下,默認的nginx使用的組。如果沒有指定,默認為 nobody。 --group=GROUP #指定編譯的目錄 --builddir=DIR #啟用 rtsig 模塊 --with-rtsig_module #允許或不允許開啟SELECT模式,如果configure沒有找到合適的模式,比如,kqueue(sun os)、epoll(linux kenel 2.6+)、rtsig(實時信號) --with-select_module(--without-select_module) #允許或不允許開啟POLL模式,如果沒有合適的,則開啟該模式。 --with-poll_module(--without-poll_module) #開啟HTTP SSL模塊,使NGINX可以支持HTTPS請求。這個模塊需要已經安裝了OPENSSL,在DEBIAN上是libssl-dev --with-http_ssl_module --with-http_realip_module #啟用 ngx_http_realip_module --with-http_addition_module #啟用 ngx_http_addition_module --with-http_sub_module #啟用 ngx_http_sub_module --with-http_dav_module #啟用 ngx_http_dav_module --with-http_flv_module #啟用 ngx_http_flv_module --with-http_stub_status_module #啟用 "server status" 頁 --without-http_charset_module #禁用 ngx_http_charset_module --without-http_gzip_module #禁用 ngx_http_gzip_module. 如果啟用,需要 zlib 。 --without-http_ssi_module #禁用 ngx_http_ssi_module --without-http_userid_module #禁用 ngx_http_userid_module --without-http_access_module #禁用 ngx_http_access_module --without-http_auth_basic_module #禁用 ngx_http_auth_basic_module --without-http_autoindex_module #禁用 ngx_http_autoindex_module --without-http_geo_module #禁用 ngx_http_geo_module --without-http_map_module #禁用 ngx_http_map_module --without-http_referer_module #禁用 ngx_http_referer_module --without-http_rewrite_module #禁用 ngx_http_rewrite_module. 如果啟用需要 PCRE 。 --without-http_proxy_module #禁用 ngx_http_proxy_module --without-http_fastcgi_module #禁用 ngx_http_fastcgi_module --without-http_memcached_module #禁用 ngx_http_memcached_module --without-http_limit_zone_module #禁用 ngx_http_limit_zone_module --without-http_empty_gif_module #禁用 ngx_http_empty_gif_module --without-http_browser_module #禁用 ngx_http_browser_module --without-http_upstream_ip_hash_module #禁用 ngx_http_upstream_ip_hash_module --with-http_perl_module - #啟用 ngx_http_perl_module --with-perl_modules_path=PATH #指定 perl 模塊的路徑 --with-perl=PATH #指定 perl 執行文件的路徑 --http-log-path=PATH #Set path to the http access log --http-client-body-temp-path=PATH #Set path to the http client request body temporary files --http-proxy-temp-path=PATH #Set path to the http proxy temporary files --http-fastcgi-temp-path=PATH #Set path to the http fastcgi temporary files --without-http #禁用 HTTP server --with-mail #啟用 IMAP4/POP3/SMTP 代理模塊 --with-mail_ssl_module #啟用 ngx_mail_ssl_module --with-cc=PATH #指定 C 編譯器的路徑 --with-cpp=PATH #指定 C 預處理器的路徑 --with-cc-opt=OPTIONS # --with-ld-opt=OPTIONS #Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt="-L /usr/local/lib". --with-cpu-opt=CPU #為特定的 CPU 編譯,有效的值包括:pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64 --without-pcre #禁止 PCRE 庫的使用。同時也會禁止 HTTP rewrite 模塊。在 "location" 配置指令中的正則表達式也需要 PCRE 。 --with-pcre=DIR #指定 PCRE 庫的源代碼的路徑。 --with-pcre-opt=OPTIONS #設置PCRE的額外編譯選項。 --with-md5=DIR #使用MD5匯編源碼。 --with-md5-opt=OPTIONS #Set additional options for md5 building. --with-md5-asm #Use md5 assembler sources. --with-sha1=DIR #Set path to sha1 library sources. --with-sha1-opt=OPTIONS #Set additional options for sha1 building. --with-sha1-asm #Use sha1 assembler sources. --with-zlib=DIR #Set path to zlib library sources. --with-zlib-opt=OPTIONS #Set additional options for zlib building. --with-zlib-asm=CPU #Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro --with-openssl=DIR #Set path to OpenSSL library sources --with-openssl-opt=OPTIONS #Set additional options for OpenSSL building --with-debug #啟用調試日志 --add-module=PATH #Add in a third-party module found in directory PATH 在不同版本間,選項可能會有些許變化,請總是使用 ./configure --help 命令來檢查一下當前的選項列表。