zoukankan      html  css  js  c++  java
  • nginx搭建笔记

    1. nginx安装

    Env: Mac OS 10.10 Yosemite

    pcre: http://pcre.org/

    $tar -zxf pcre-8.34.tar.gz
    $cd pcre-8.34
    $./configure
    $make 
    $sudo make install

    zlib: http://zlib.net/

    $tar -zxf zlib-1.2.8.tar.gz
    $cd zlib-1.2.8
    $./configure
    $make
    $sudo make install

    openssl: http://www.openssl.org/source/

    $tar -zxf openssl-1.0.1j.tar.gz
    $cd openssl-1.0.1j
    $./config

    注意下此时会有提示要编译64位版本需要用另外的指令

    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.html

    $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为服务器安装目录

    $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

     2. nginx启用gzip压缩

    参数设置可参考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;

    3. nginx缓存时间控制

    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;
            }
  • 相关阅读:
    关于springboot项目使用yml类型的配置文件
    关于个人电脑连不上公司svn服务器,显示拒绝访问的错误
    改变思考问题的方式——SQL排序查询
    FreeMarker入门级
    个人电脑安装svn实录
    tomcat配置虚拟路径,可以解决实际开发中测试时前端访问后台电脑上的图片的问题
    springmvc的运行原理个人见解
    [CF915F] Imbalance Value of a Tree
    [CF768G] The Winds of Winter
    [BZOJ4241] 历史研究
  • 原文地址:https://www.cnblogs.com/engineermind/p/4174924.html
Copyright © 2011-2022 走看看