location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if (-f $request_filename) { access_log off; expires 30d; break; } if (!-f $request_filename) { proxy_pass http:
Above, it will serve all existing files directly using Nginx (for example, Nginx just displays the PHP source code), otherwise it redirects the request to Apache. I need to exclude * .php files from the rule so that requests for * .php are also transferred to Apache and processed.
I want Nginx to process all static files and Apache to process all dynamic materials.
EDIT: There is a whitelist, but it is not very elegant, see all these extensions, I do not want this.
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ { access_log off; expires 30d; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; }
EDIT 2: In newer versions of Nginx use try_files instead of http://wiki.nginx.org/HttpCoreModule#try_files
reverse-proxy nginx static-files
F. Malina May 15, '09 at 14:24 2009-05-15 14:24
source share