大网数据广告活动
服务器运维问答

What is the purpose of magic try_files statement?

· 52CE 我爱测

Maintaining the system which was setup by a 3rd party found the following in the nginx vhost configuration server { listen *:80; listen *:443 ssl; ssl_certificate /path/to/cert.crt; ssl_certificate_key /path/to/cert.key; server_n…

问题原文

原帖链接 · Anton Boritskiy · CC BY-SA 3.0

Maintaining the system which was setup by a 3rd party found the following in the nginx vhost configuration

server {
    listen *:80;

    listen *:443 ssl;
    ssl_certificate /path/to/cert.crt;
    ssl_certificate_key /path/to/cert.key;

    server_name <server-name-here>;

    root   /path/to/vhost/root;

    index index.html index.htm index.php index.cgi index.pl index.xhtml;

    error_log /var/log/ispconfig/httpd/domain-name/error.log;
    access_log /var/log/ispconfig/httpd/domain-name/access.log combined;

    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /stats/ {
        index index.html index.php;
        auth_basic "Members Only";
        auth_basic_user_file /path/to/passwd/file;
    }

    location ^~ /awstats-icon {
        alias /usr/share/awstats/icon;
    }

    location ~ \.php$ {
        try_files /0816f18c2383162111fc93fe015c1607.htm @php;
    }

    location @php {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9010;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;

        include fastcgi_params;
        fastcgi_read_timeout 300;
    }

    client_max_body_size 24M;

    location / {
       try_files $uri $uri/ /index.php?$args;
       add_header 'Access-Control-Allow-Origin' '*.domain.name';
       add_header 'Access-Control-Allow-Methods' 'GET, POST';

       satisfy any;
       allow <white-listed-IPs>;
       deny all;
            auth_basic "Members Only";
            auth_basic_user_file /path/to/passwd/file;

            location ~ \.php$ {
                try_files /0816f18c2383162111fc93fe015c1607.htm @php;
            }
    }

    location ~* ^.+.(css|js|jpg|jpeg|png|gif|ico|woff|ttf|otf|eot|svg|pdf)$ {
        access_log off;
        expires 1h;
    }
}

which looks pretty straightforward to me except this try_files /0816f18c2383162111fc93fe015c1607.htm @php; statement. There is no file with that name on the disk. Apparently this is some sort of magic used for monitoring or switching the vhost off, hard to google for it since the filename is totally random string.

Any idea what is that used for?

P.S. We are talking about Linux machine, it also has ISPConfig installed, not sure if that matters. Nginx version was 1.2.0 when I took the machine over.

已采纳解答

原帖链接 · Tero Kilkanen · CC BY-SA 3.0

One legitimate use for this try_files entry is to make it easy to enter site into maintenance mode. Once this file is created on the web server, no PHP scripts are executed, only that particular .htm file is displayed.

During the maintenance it would be easier to perform complex updates without making site break in unexpected ways.

The filename is chosen to be this so that it wouldn't clash with any other .htm file on the site.

However, this way of implementing maintenance mode would break all other non-HTML content pages during maintenance period, like RSS feeds, sitemaps and JSON APIs.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。