Nginx 目前來講已經很流行了,因此打算把現有的Apache先替換一部分,在批量部署和管理方面都要考慮到。由於nginx的全部模塊都是靜態編譯的不像apache那樣能夠動態添加模塊,因此在一開始就要考慮清楚需求,結合如今很火的LAMP模式,其中P最多見的是PHP,目前較好的FastCGI的管理器有spaw-fcgi和php-fpm,而php老版本都是須要源碼安裝經過打補丁的方式把php-fpm打進去,spaw-fcgi是lighttpd默認的FastCGI管理器,由於牽扯到源碼安裝,當前的軟件包版本在大規模部署起來不是很方便,可是仍是有解決辦法的。 php
Nginx安裝方法: mysql
1 apt網絡安裝 nginx
修改源列表 算法
vi /etc/apt/sources.list #加入如下源 deb http://nginx.org/packages/debian/ squeeze nginx deb-src http://nginx.org/packages/debian/ squeeze nginx
更新源列表並經過apt安裝nginx sql
apt-key add nginx_signing.key apt-get update apt-get install nginx
2 源碼編譯安裝
先安裝編譯環境, 因爲nginx在之後的使用中會須要用到perl正則、壓縮算法、SSL等特性,因此咱們須要提早安裝相關庫文件。 shell
apt-get install build-essential apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev libssl0.9.8
下載最新的穩定版nginx apache
wget http://nginx.org/download/nginx-1.2.3.tar.gz
解壓查看編譯選項 後端
tar zxvf nginx-1.2.3.tar.gz cd nginx-1.2.3 #--help能夠看到能夠配置的參數 ./configure --help
查看編譯可選的配置參數(如下只是一些經常使用的配置項): 瀏覽器
--prefix=PATH nginx的默認安裝路徑,沒有指定的話。默認爲/usr/local/nginx 安全
--sbin-path=PATH nginx可執行命令文件的路徑,沒有指定的話,默認<prefix>/sbin/nginx
--conf-path=PATH nginx配置文件路徑,沒有指定的話,默認爲<prefix>/conf/nginx.conf
--error-log-path=PATH 在nginx.conf中沒有使用error_log指定錯誤日誌路徑時,默認<prefix>/logs/error.log
--http-log-path=PATH 定義被訪問文件的日誌存放路徑,若是在nginx.conf中沒有使用access_log指定,默認爲<prefix>/logs/access.log
--pid-path=PATH 當在nginx.conf中沒有使用pid指定pid文件路徑時,默認爲<prefix>/logs/nginx.pid
--lock-path=PATH 鎖文件存放路由,若是在nginx.conf中沒有指定,則默認爲<prefix>/logs/nginx.lock
--user=USER 若是在Nginx.conf中沒有使用user定義進程運行的屬主,則默認爲nobody
--group=GROUP 若是在Nginx.conf中沒有使用user定義進程運行的屬組,則默認爲nobody
--builddir=DIR set build directory
--with-rtsig_module 使用rtsig模式
--with-select_module 使用select模式,若是當前平臺沒有其餘有效模式,則默認編譯
--without-select_module 禁止select模式
--with-poll_module 使用poll模式,若是當前平臺沒有其餘有效模式,則默認編譯
--without-poll_module 禁止poll模式
--with-file-aio enable file AIO support
--with-ipv6 開啓IPV6支持
--with-debug 開啓debug
如下這些模塊默認沒有開啓,可使用--with命令開啓如下模塊
--with-http_ssl_module 開啓ssl模塊
--with-http_realip_module 能夠在後端記錄客戶端IP
--with-http_addition_module enable ngx_http_addition_module
--with-http_flv_module 開啓flv模塊
--with-http_mp4_module 開啓mp4模塊
--with-http_gzip_static_module 開啓gzip模塊
--with-http_secure_link_module enable ngx_http_secure_link_module
--with-http_stub_status_module 開啓狀態查看模塊
如下模塊默認是開啓的,可使用--without選項關閉相關模塊
--without-http_charset_module disable ngx_http_charset_module
--without-http_gzip_module 禁用gzip壓縮模塊
--without-http_ssi_module 禁用ssl模塊
--without-http_userid_module disable ngx_http_userid_module
--without-http_access_module 禁用access模塊
--without-http_auth_basic_module 禁用auth_basic認證模塊
--without-http_autoindex_module 禁用列目錄模塊
--without-http_geo_module 禁用geo模塊
--without-http_map_module 禁用map模塊
--without-http_referer_module disable ngx_http_referer_module
--without-http_rewrite_module 禁用重定向模塊
--without-http_proxy_module 禁用代理模塊
--without-http_fastcgi_module 禁用fastcgi模塊
--without-http_uwsgi_module disable ngx_http_uwsgi_module
--without-http_scgi_module disable ngx_http_scgi_module
--without-http_memcached_module disable ngx_http_memcached_module
--without-http_limit_conn_module disable ngx_http_limit_conn_module
--without-http_limit_req_module disable ngx_http_limit_req_module
--without-http_empty_gif_module disable ngx_http_empty_gif_module
--without-http_browser_module disable ngx_http_browser_module
--without-http_upstream_ip_hash_module 禁用upstream模塊
--with-http_perl_module 開啓perl模塊--with-perl_modules_path=PATH 設置perl模塊路徑--with-perl=PATH 爲perl庫設置路徑--http-client-body-temp-path=PATH set path to store http client request body temporary files--http-proxy-temp-path=PATH set path to store http proxy temporary files--http-fastcgi-temp-path=PATH set path to store http fastcgi temporary files--http-uwsgi-temp-path=PATH set path to store http uwsgi temporary files--http-scgi-temp-path=PATH set path to store http scgi temporary files--without-http 禁用http服務--without-http-cache 禁用http cache--with-mail 開啓mail服務--with-mail_ssl_module 在mail服務中開啓ssl--without-mail_pop3_module disable ngx_mail_pop3_module--without-mail_imap_module disable ngx_mail_imap_module--without-mail_smtp_module disable ngx_mail_smtp_module--with-google_perftools_module 開啓google_perftools模塊--with-cpp_test_module 開啓cpp_test模塊--add-module=PATH enable an external module--without-pcre 禁止使用perl正則庫--with-pcre 強制使用perl正則庫
./configure --prefix=/etc/nginx/ --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-ipv6結果以下圖:
make && make installFastCGI回顧
vi /etc/apt/sources.list deb http://packages.dotdeb.org stable all deb-src http://packages.dotdeb.org stable all更新源列表,安裝php5-fpm
apt-get update wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - apt-get install php5-fpm安裝其餘經常使用php5組件
apt-get install php5 php5-cgi php5-cli php5-mysql php5-memcache啓動php-fpm
/etc/init.d/php5-fpm start