Welcome! Log In Create A New Profile

Advanced

try_files does not work.

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

I am migrating from Apache server to Nginx.

I am finding it very difficult. My Nginx version is 0.8.5.3 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 127.0.0.1:9000
location ~ \.php$ {

root /home/vhosts/testdomain.com/httpdocs;
fastcgi_pass 127.0.0.1:9000;
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 127.0.0.1:9000

location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}

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

Andrejs
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 158
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready