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;
}