This is solved. Removing that and replacing it with
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
break;
}
did the trick. There's some talk about if is evil with nginx but unless somebody can give me a working example with try_files, I'm stuck with this.
I'm trying to get WP to work with Nginx (1.1.19) but I'm having problems with the blog index. Everything else works perfectly except for some reason nginx servers the php file as downloadable to the browser when I try to visit it. Admin backend and all the posts work with permalinks and everything.
I'm not a noob so I have googled and read but I just can't seem to get this solved. Any ideas?
This is my current nginx site conf:
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
# .domain.com will match both domain.com and anything.domain.com
server_name .foo.com;
# It is best to place the root of the server block at the server level, and not the location level
# any location block path will be relative to this root.
root /var/www;
# It's always good to set logs, note however you cannot turn off the error log
# setting error_log off; will simply create a file called 'off'.
access_log /var/log/nginx/foo.access.log;
error_log /var/log/nginx/foo.error.log;
# This can also go in the http { } level
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress' virtual robots.txt
location = /favicon.ico { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /var/www;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
location ~ \.php {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}