zoukankan      html  css  js  c++  java
  • nginx try_files

    pgc?Id=123
    ---》
    /#pgc?Id=123

    location / {
    try_files $uri /#$uri /index.html;
    }

    vue 去除/#/

    Module ngx_http_core_module http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

    Syntax: try_files file ... uri;
    try_files file ... =code;
    Default:
    Context: serverlocation

    Checks the existence of files in the specified order and uses the first found file for request processing; the processing is performed in the current context. The path to a file is constructed from the file parameter according to the root and alias directives. It is possible to check directory’s existence by specifying a slash at the end of a name, e.g. “$uri/”. If none of the files were found, an internal redirect to the uri specified in the last parameter is made. For example:

    location /images/ {
        try_files $uri /images/default.gif;
    }
    
    location = /images/default.gif {
        expires 30s;
    }
    

    The last parameter can also point to a named location, as shown in examples below. Starting from version 0.7.51, the last parameter can also be a code:

    location / {
        try_files $uri $uri/index.html $uri.html =404;
    }
    

    Example in proxying Mongrel:

    location / {
        try_files /system/maintenance.html
                  $uri $uri/index.html $uri.html
                  @mongrel;
    }
    
    location @mongrel {
        proxy_pass http://mongrel;
    }
    

    Example for Drupal/FastCGI:

    location / {
        try_files $uri $uri/ @drupal;
    }
    
    location ~ .php$ {
        try_files $uri @drupal;
    
        fastcgi_pass ...;
    
        fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
        fastcgi_param QUERY_STRING    $args;
    
        ... other fastcgi_param's
    }
    
    location @drupal {
        fastcgi_pass ...;
    
        fastcgi_param SCRIPT_FILENAME /path/to/index.php;
        fastcgi_param SCRIPT_NAME     /index.php;
        fastcgi_param QUERY_STRING    q=$uri&$args;
    
        ... other fastcgi_param's
    }
    

    In the following example,

    location / {
        try_files $uri $uri/ @drupal;
    }
    

    the try_files directive is equivalent to

    location / {
        error_page 404 = @drupal;
        log_not_found off;
    }
    

    And here,

    location ~ .php$ {
        try_files $uri @drupal;
    
        fastcgi_pass ...;
    
        fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
    
        ...
    }
    

    try_files checks the existence of the PHP file before passing the request to the FastCGI server.

    Example for Wordpress and Joomla:

    location / {
        try_files $uri $uri/ @wordpress;
    }
    
    location ~ .php$ {
        try_files $uri @wordpress;
    
        fastcgi_pass ...;
    
        fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
        ... other fastcgi_param's
    }
    
    location @wordpress {
        fastcgi_pass ...;
    
        fastcgi_param SCRIPT_FILENAME /path/to/index.php;
        ... other fastcgi_param's
    }
  • 相关阅读:
    CCF-CSP201512-3 画图
    CCF-CSP201512-2 消除类游戏
    CCF-CSP201606-4 游戏(BFS)
    CCF-CSP201604-2 俄罗斯方块
    HDU1035 Robot Motion(dfs)
    Java Srting之Calendar日历类(五)——Calendar中计算时间的方法add()
    java如何获取当前日期和时间
    double 类型怎样不用科学计数法表示并且使用Java正则表达式去掉Double类型的数据后面多余的0
    @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})注解作用
    java.util.Date.toString()方法实例
  • 原文地址:https://www.cnblogs.com/rsapaper/p/14897161.html
Copyright © 2011-2022 走看看