Welcome! Log In Create A New Profile


try_files does not work.

Posted by nilicon 
try_files does not work.
October 05, 2011 11:22AM

I am migrating from Apache server to Nginx.

I am finding it very difficult. My Nginx version is on Redhat server.

Below is my conf file.
server {
listen www.testdomain.com:80;
server_name www.testdomain.com testdomain.com;

location / {
root /home/vhosts/testdomain.com/httpdocs/;
index index.php index.html index.htm;

rewrite "^/us$" /us/ permanent; break;

#if (!-f $request_filename){
# set $rule_3 1$rule_3;
#if (!-d $request_filename){
# set $rule_3 2$rule_3;
#if ($rule_3 != "21"){
# rewrite /. /rewriteurl.php;

try_files $uri /rewriteurl.php;

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {

root /home/vhosts/testdomain.com/httpdocs;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

include fastcgi_params;
fastcgi_intercept_errors on;
error_page 404 $document_root/errorpage.php;


As you can see I am simply trying to do redirection of non existing files or directory into one single file rewriteurl.php where I am handing all the rewriteurl cases.

I have also tried to setup using if -d and -f option but that also does not seem to work.

But somehow this is not working.

Can some buddy help me. I am in deep trouble here???

Any ideas?

Thanks in Advance.
Nilicon Jefferson.
Re: try_files does not work.
October 13, 2011 07:07AM
1. move the root directive outside the "location /" block into the server block

2. move "error_page 404 /errorpage.php" into the server block

2. alter fastcgi configuration as described below:

# pass the PHP scripts to FastCGI server listening on

location ~ \.php$ {
include fastcgi_params;

3. remove: "rewrite "^/us$" /us/ permanent; break;" as it makes no sense

4. move "fastcgi_intercept_errors on;" into the http block

5. go and see the manual, find example configurations on google and learn from those

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready