Why my php file in subdirectory doesn't work?

Hello everyone,

I am working on an centos6 with nginx 1.0.6, php 5.3.6, and fpm.

I found that php file in my subdirectory returns a 404,but in nginx home
direcory works fine.

For example , a phpinfo.php file works fine in /data/web/, where
/data/web is my nginx document root. Buy the same file in /data/web/sub,
the browser and nginx both tell a 404 error.

Here is my nginx config file:

server {
    listen       80;
    server_name  abc.example.com;

    location / {
        root   /data/web/;
        index  index.html index.htm index.php;

location ~ .*\.(php|php5)?$
    {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    }
    }
    }

btw, static file such as html works fine.

Thans a lot.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,215921#msg-215921

Hello.

You shoude set (fastcgi_param SCRIPT_FILENAME) .

example:
location ~ .*.(php|php5)?$
{
fastcgi_param SCRIPT_FILENAME /data/web/$1;

   }

On Wed, Sep 28, 2011 at 10:56 AM, baalchina [email protected]
wrote:

   fastcgi_busy_buffers_size 128k;

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,215921#msg-215921


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


douban:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: www.twitter.com/minibobo

weibo: www.weibo.com/diaoliang

I have similar problem. I can get the index.php to display in the
document root, but when I type www.mydomain.com/administrator it will
not pull the index.php, but if I type
www.mydomain.com/administrator/index.php, it will bring the page up. So
is this a configuration file issue or a rewrite issue. I need to resolve
this due to the fact I have some joomla installs that have a root joomla
install and then a subdirectory of joomla installed and I must be able
to get the server to respond to the sub-directory index.php files.

I am new to NGINX and let me say it is awesome, but I still have a lot
to learn.

Thx
Suttles

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,216516#msg-216516

I have the variable set, or at least I think I do. Here is my config for
the vhost.

server {
client_max_body_size 20M;
listen 1192;
# .domain.com will match both domain.com and
anything.domain.com
server_name rentavault.net;

    # 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 /home/www/rentavault_net;

    # 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 /home/www/rentavault_net/logs/access_log.log main;
error_log /home/www/rentavault_net/logs/error_log.log info;

    # This can also go in the http { } level
    index index.php index.html;

    location / {
            # if you're just using wordpress and don't want extra

rewrites
# then replace the word @rewrites with /index.php
try_files $uri $uri/ @rewrites;
}
location ~ ^/cgi-bin/(awredir|awstats).pl {
gzip off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
$document_root/cgi-bin/cgi-bin.php;
fastcgi_param X_SCRIPT_FILENAME
/home/www/rentavault_net/$fastcgi_script_name;
fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}

This config will not let me access the sub directory without index.php
in the path of the browser. Very frustrating.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,216519#msg-216519

Thanks!

You should set index directive. example: “index index.html index.php”

On Tue, Oct 11, 2011 at 10:53 PM, suttles [email protected] wrote:

to learn.
http://mailman.nginx.org/mailman/listinfo/nginx


douban:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: www.twitter.com/minibobo

weibo: www.weibo.com/diaoliang

Thanks!

You should add fastcgi_index index.php.

On Tue, Oct 11, 2011 at 11:21 PM, suttles [email protected] wrote:

   # It is best to place the root of the server block at the server

           gzip off;

in the path of the browser. Very frustrating.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,216519#msg-216519


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


douban:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: www.twitter.com/minibobo

weibo: www.weibo.com/diaoliang

Ok, tried that, I have a suspicion that I may have a load balancer issue
happening as well. Will report back. I was suppose to add fastcgi_index
to the line of

index index.php index.html;

to look like
index fastcgi_index index.php index.html;

right?

Thx
Doug

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,216602#msg-216602

Update on my problem… if the URL is typed this way
http://www.domain.com/subdirectory it will not pull up the site, but
when the URL is typed http://www.domain.com/subdirectory/ the site comes
up immediately. How to do force nginx to put the trailing slash onto the
subdomains?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,216831#msg-216831

On 06/01/2012 07:37, gigabyte wrote:

    fastcgi_param SCRIPT_FILENAME $sroot/$fastcgi_script_name ;

I suspect this should be

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Regards

Ian


Ian H.
31 Sheerwater, Northampton NN3 5HU,
Tel: 01604 513875
Preparing eBooks for Kindle and ePub to give the best reader experience.

I have the same problem with subdirectories. My config Is:
set $sroot /usr/local/www/
location ~ .php$ {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $sroot/$fastcgi_script_name ;
fastcgi_param QUERY_STRING $query_string;
fastcgi_pass 127.0.0.1:9000;
fastcgi_intercept_errors on;
break;
}

location / {
   root $sroot ;
   index index.php;
}

By the way I think it all happend when I’ve upgraded from nginx 0.9 to
1.0.11. I think that my original configs had been replaced with new
ones.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220863#msg-220863

On Mon, Oct 17, 2011 at 11:19 PM, suttles [email protected] wrote:

Update on my problem… if the URL is typed this way
http://www.domain.com/subdirectory it will not pull up the site, but
when the URL is typed http://www.domain.com/subdirectory/ the site comes
up immediately. How to do force nginx to put the trailing slash onto the
subdomains?

either

location = /subdirectory {
rewrite ^ $uri/?$args permanent;
}

or

try_files $uri $uri/ =404;

or

symlink in root instead of redefining root in location /subdirectory/

or

location /subdirectory {

}
##note that this one kind of not what you expect.
/subdirectorysomething will match this location.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

I’ve already tried meny variations including this one. In fact I’m using
it right now with some modifications:

location / {
    root $sroot;
    index  index.php index.html index.htm;
    if (-e $request_filename) {
        break;
    }
    rewrite ^/(.+)$ /index.php?q=$1 last;
}
 if ($host !~* ^www\.) {
    rewrite ^(.*)$ http://www.$host$1 permanent;
}

location = /administrator {
    rewrite ^ $uri/?$args permanent;
}

location ~ \.php$ {
    root $sroot;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME

$document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}

location ~ /\.ht {
    deny  all;
}

But it keeps redirecting me to document_root instead of
document_root/subdirectory

Also I know that It worked before some one put his hands on my config
files.

hobson42 Wrote:

nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220872#msg-220872

On Fri, Jan 6, 2012 at 6:39 PM, gigabyte [email protected] wrote:

I’ve already tried meny variations including this one. In fact I’m using
it right now with some modifications:

Post the full config.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Here is my full config
server {

set $sroot /services/www/site;

listen      192.168.170.1:80;
server_name  site.net www.site.net;
access_log  /var/log/nginx/site.net.access.log  main;
error_log  /var/log/nginx/site.net.error.log info;

location = /administrator {
    root $sroot/administrator;
}

location / {
    root $sroot;
    index  index.php index.html index.htm;
    if (-e $request_filename) {
        break;
    }
    rewrite ^/(.+)$ /index.php?q=$1 last;
}
 if ($host !~* ^www\.) {
    rewrite ^(.*)$ http://www.$host$1 permanent;
}


location ~ \.php$ {
    root $sroot;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME

$document_root$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}

location ~ /\.ht {
    deny  all;
}

}

Edho A. Wrote:

On Fri, Jan 6, 2012 at 6:39 PM, gigabyte
[email protected] wrote:

I’ve already tried meny variations including
this one. In fact I’m using
it right now with some modifications:

Post the full config.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220874#msg-220874

No, this did not work either.
nginx keeps looking for for relative files in a directory, but
has to do it in /administrator directory
Maybe some other suggestions ?
Edho A. Wrote:


O< ascii ribbon campaign - stop html mail -
www.asciiribbon.org


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220882#msg-220882

On Fri, Jan 6, 2012 at 7:26 PM, gigabyte [email protected] wrote:

Here is my full config
server {

Try this instead:

http://pastie.org/3137133


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

On Fri, Jan 6, 2012 at 8:46 PM, gigabyte [email protected] wrote:

No, this did not work either.
nginx keeps looking for for relative files in a directory, but
has to do it in /administrator directory
Maybe some other suggestions ?

What do you mean? Are the files located in
/services/www/site/administrator/administrator/?


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

the Root directory is /services/www/site/

When I login into the index.php which is located in
/services/www/site/administrator
nginx redirects me to index.php which is located in the root directory -
/services/www/site

When I manually enter site.net/administrator/index.php it opens the
right file but all relative links on it (css,js, ,…etc) are being
loaded from root directory (/services/www/site) and thay should be
loaded from subdirectory (/services/www/site/administrator) and that is
why I’m getting many 404 responses from server.

Edho A. Wrote:


O< ascii ribbon campaign - stop html mail -
www.asciiribbon.org


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220885#msg-220885

On Fri, Jan 6, 2012 at 9:01 PM, gigabyte [email protected] wrote:

loaded from subdirectory (/services/www/site/administrator) and that is
why I’m getting many 404 responses from server.

Looks like application configuration problem.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

May be but this all started when I’ve updated nginx from 1.0.4 to 1.0.9
This update erased all my previous config files and I’ve started from
beginning
and stuck on this problem
Edho A. Wrote:

http://mailman.nginx.org/mailman/listinfo/nginx
Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215921,220888#msg-220888

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs