nginx使用

nginx使用

一、nginx安装

详见:http://blog.csdn.net/zhengyong15984285623/article/details/53871752

一、nginx配置信息

查看命令nginx -V,结果如下所示:

nginx version: nginx/1.10.1
built by clang 7.0.2 (clang-700.1.81)
built with OpenSSL 1.0.2h  3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.10.1 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.10.1/bin/nginx --with-cc-opt='-I/usr/local/Cellar/pcre/8.38/include -I/usr/local/Cellar/openssl/1.0.2h_1/include' --with-ld-opt='-L/usr/local/Cellar/pcre/8.38/lib -L/usr/local/Cellar/openssl/1.0.2h_1/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module
二、nginx常用命令
命令备注
nginx启动命令
nginx -s stop强制迅速关闭nginx进程
nginx -s quit优雅关闭nginx进程
nginx -s reload重新加载配置文件
nginx -s reopen重新打开log文件
nginx -t测试并检测nginx.conf语法
nginx -v输出nginx版本
nginx -V输出nginx版本和配置信息
nginx -c file使用指定的nginx.conf配置文件
三、location说明

安装默认location位置是/usr/local/Cellar/nginx/1.10.1/

server {

    # 1.根路径
    location / {
        root /data/www;
    }

     # 2.路径前缀(相对路径,相对/usr/local/Cellar/nginx/1.10.1)
    location /images/ {
        root /data;
    }

    # 3.别名路径(绝对路径),与2(路径前缀)一样
    location /alias/images/ {
        alias /usr/local/Cellar/nginx/1.10.1/data/images/;
    }

    # 4.反向代理
    location / {
        proxy_pass http://localhost:8080/;
    }

    # 5.正则
    location ~ \.(gif|jpg|png)$ {
        root /data/images;
    }
}
  1. location匹配首先是根据最长路径优先匹配原则,比如http://localhost/images/example.png, 这时候nginx首先把请求转向/data/images/example.png, 如果没有则返回404页面。
  2. 当nginx选择一个location来提供请求时,它首先检查指定前缀的位置指令,记住具有最长前缀的location,然后检查正则表达式。 如果存在与正则表达式的匹配,nginx选择此location,否则,它选择先前记住的位置。
四、nginx系统日志

不同操作系统日志可能出现位置不同,比如下面两种情况,mac为第一种:

# log location 1
/usr/local/var/log/nginx/access.log
/usr/local/var/log/nginx/error.log

# log location 2
/var/log/nginx/access.log
/var/log/nginx/error.log
五、参考文档

官方文档地址:http://nginx.org/en/docs/beginners_guide.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值