zoukankan      html  css  js  c++  java
  • Nginx配置

    配置简介

    1)nginx相关目录

    工作目录:/etc/nginx
    执行文件:/usr/sbin/nginx
    日志目录:/var/log/nginx
    启动文件:/etc/init.d/nginx
    web目录:/var/www/html/,首页文件是index.nginx-debian.html
    

    2)nginx配置文件

    默认文件:
    /etc/nginx/nginx.conf
    其他目录:
    /etc/nginx/{sites-available/sites-enabled/conf.d}
    文件结构:
        全局配置段
        http配置段
            server配置段          # 项目或者应用
                location配置段    # url配置
    

    • nginx访问原理

    nginx配置详解


    ==================================================================


    location配置段

    ==================================================================

    • @name示例 @用来定义一个命名location。主要用于内部重定向,不能用来处理正常的请求。其用法如下:
    location / {
        try_files $uri $uri/ @custom;
    }
    location @custom {
        # ...do something
        # custom 命名的 location中不能再嵌套其它的命名location
    }
    
    • 关于URL尾部的/有如下注意事项

    URL尾部的"/"表示目录,没有"/"表示文件,而且文件找不到的话,会发生重定向。
    /other/:表示服务器会自动去该目录下找对应的默认文件。
    /other:表示服务器会先去找other文件,找不到的话会将other当成目录,重定向到/other/,去该目录下找默认文件。

    location核心动作

    try_files

    location常见动作




    location /img {
    	alias /var/www/html/img/;
    	try_files $uri $uri/ =404;
    }
    > http://127.0.0.1:80/img/1.jpg -> /var/www/image/1.jpg
    
    
    
    
    location /img {
    	root /var/www/html/img/;
    	try_files $uri $uri/ =404;
    }
    > http://127.0.0.1:80/img/1.jpg -> /var/www/image/img/1.jpg
    
  • 相关阅读:
    算法面试题解答(三)
    计算机基础知识问答
    算法面试题解答(五)
    关于POD
    算法面试题解答(四)
    算法面试题解答(一)
    Perfect Interview (序)
    如何调整Dreamhost主机PHP上传尺寸的限制/How to change the maximal size of uploading in your Dreamhost
    Final Fantasy XIII Finished
    Ortholab has been moved to Google Code
  • 原文地址:https://www.cnblogs.com/oklizz/p/11336151.html
Copyright © 2011-2022 走看看