Env: Mac OS 10.10 Yosemitejavascript
pcre: http://pcre.org/css
$tar -zxf pcre-8.34.tar.gz $cd pcre-8.34 $./configure $make $sudo make install
zlib: http://zlib.net/html
$tar -zxf zlib-1.2.8.tar.gz $cd zlib-1.2.8
$./configure
$make
$sudo make install
openssl: http://www.openssl.org/source/java
$tar -zxf openssl-1.0.1j.tar.gz $cd openssl-1.0.1j $./config
注意下此時會有提示要編譯64位版本須要用另外的指令nginx
WARNING! If you wish to build 64-bit library, then you have to invoke './Configure darwin64-x86_64-cc' *manually*. You have about 5 seconds to press Ctrl-C to abort.
$make clean $./Configure darwin64-x86_64-cc $make $sudo make install
nginx: http://nginx.org/en/download.htmlapache
$tar -zxf nginx-1.7.8.tar.gz $cd nginx-1.7.8 $./configure --with-http_ssl_module $make $sudo make install
安裝完畢,/usr/local/nginx爲服務器安裝目錄json
$cd /usr/local/nginx $ls conf html logs sbin
conf爲服務器配置目錄,編輯nginx.conf啓用各類模塊瀏覽器
html爲網站文件目錄,存放html/js/css等文件緩存
sbin爲nginx可執行文件,服務器
$./sbin/nginx -h nginx version: nginx/1.7.8 Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
啓動nginx服務器: sudo /usr/local/nginx/sbin/nginx
這時候打開瀏覽器輸入http://localhost/能顯示Welcome to nginx!表示配置成功
中止、重啓等操做經過-s參數,例如修改配置後重啓:sudo /usr/local/nginx/sbin/nginx -s reload
參數設置可參考http://www.cnblogs.com/dasn/articles/4043989.html
其中gzip_types可參照nginx/conf/mime.types的映射進行設置,比apache方便很多
例如:
gzip on; gzip_types text/plain text/html text/xml application/javascript application/json; gzip_comp_level 4; gzip_http_version 1.0;
expires [time|epoch|max|off]
默認off
time: 可爲正負數,負數表示永遠過時
epoch: 指定爲1 January, 1970, 00:00:01 GMT
max: 指定爲31 December 2037 23:59:59 GMT
例如:
location ~ \.(jpg|ico|png|jpeg|js|json|html|txt)$ {
expires 30d;
}