Rewrite and try_files in Nginx

Source: Internet
Author: User
Looking at the Yii documentation today, we found that the recommended Nginx configuration parameters are:

Location/{

# Redirect everything that isn ' t a real file to index.php

Try_files $uri $uri//index.php$is_args$args;

}

Location ~ \.php$ {

Include Fastcgi_params;

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Fastcgi_pass 127.0.0.1:9000;

#fastcgi_pass Unix:/var/run/php5-fpm.sock;

Try_files $uri = 404;

}

My local use of the original parameter configuration or: Rewrite ^/(. *) $/index.php/$1 last;


Rewrite is an Apache-like configuration

The configuration here is also easier to understand, but why is the official recommendation to recommend Try_files?


Finally I found an answer: Nginx is generally used in conjunction with FPM,

If you use rewrite to redirect all files and send them to php-fpm including static files, this configuration is not recommended now.


Reference: http://blog.wuxu92.com/nginx-rewrite-and-try-files/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.