简体   繁体   English

nginx,如何提供所有静态文件并将所有其他流量转发到fastcgi

[英]nginx, how to serve all static files and forward all other traffic to a fastcgi

I want to directly serve all existent files (except .php files) 我想直接提供所有现有文件(.php文件除外)

And the rest of ALL requests (not only .php), forward them to a fastcgi server. 然后将所有其他请求(不仅是.php)转发给fastcgi服务器。

I can redirect all .php files to a fastcgi with: 我可以使用以下命令将所有.php文件重定向到fastcgi:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
}

And serve other static files with: 并通过以下方式提供其他静态文件:

location / {
}

But I want to serve first "all static files that exists and don't end with .php" And then, serve "all other requests" (not necessary ending with php) to a fastcgi, 但是我想先为“所有存在的静态文件提供,并且不以.php结尾”,然后再为fastcgi服务“所有其他请求”(不必以php结尾),

Any idea to accomplish it? 有什么想法可以实现吗?

Thanks! 谢谢!

You can use try_files for that. 您可以为此使用try_files

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;

    // other CGI parameters
}

Make sure you're aware of common pitfalls . 确保您了解常见的陷阱

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM