Reputation: 1341
I want to make nginx to look up for a specific folder to get the static html, if it doesn't found it ,it will try php file to dynamically generate the content, I tried this:
location /mysite {
try_files /mysite/path/to/static/html?$uri /mysite/path/to/php/index.php
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 2m;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
but I got 403 forbidden error, it seems like nginx only search this folder /path/to/static/html?$uri
and if not find it, will not search /path/to/php/index.php
Why this happen? How to fix it?
Thank you!
Upvotes: 0
Views: 162
Reputation: 16303
Your try_files
block isn’t quite correct and that’s the reason why it’s not working. The comment @Mohammad AbuShady left on your question is true as well, you need a semicolon at the end of the line. But your nginx shouldn’t even start with this wrong syntax so I guess this was just some typo in your question.
try_files /some/path$uri /some/path/index.php;
That’s it, simply leave out that question mark, because the question mark at this point is a literal and included in the path as is (no regular expression).
Upvotes: 2