Forum: NGINX nginx not sending DOCUMENT_ROOT to PHP?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe S. (Guest)
on 2008-11-21 19:01
(Received via mailing list)
I am using:

                location ~ \.php$ {
                        fastcgi_pass unix:/home/nginx/phpcgi/vidiscri;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME
/home/vidiscri/public_html$fastcgi_script_name;
                        fastcgi_param DOCUMENT_ROOT $document_root;
                        include conf/fastcgi_params;
                }


To send PHP over to be parsed by php-fpm , but the problem is,
DOCUMENT_ROOT variable isn't being sent to PHP it keeps saying:

_SERVER["DOCUMENT_ROOT"]  /usr/local/nginx/html

Any specific reason why its doing this?

You can check for yourself here:

http://vidiscript.aptget.com/phpinfo.php

conf/fastcgi_params has:


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_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;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
Joe S. (Guest)
on 2008-11-21 19:02
(Received via mailing list)
Figured it out.

You need to set root within the server directive, I had it set under
location.

Joe
Maxim D. (Guest)
on 2008-11-21 19:14
(Received via mailing list)
Hello!

On Fri, Nov 21, 2008 at 10:34:44AM -0600, Joe S. wrote:

>
>
> To send PHP over to be parsed by php-fpm , but the problem is,
> DOCUMENT_ROOT variable isn't being sent to PHP it keeps saying:
>
> _SERVER["DOCUMENT_ROOT"]  /usr/local/nginx/html
>
> Any specific reason why its doing this?

Any specific reason why it should do something else?  You pass
$document_root variable, and in config snipped you provided
nothing defines root to something else.

Maxim D.
Igor S. (Guest)
on 2008-11-21 19:51
(Received via mailing list)
On Fri, Nov 21, 2008 at 10:50:52AM -0600, Joe S. wrote:

> Figured it out.
>
> You need to set root within the server directive, I had it set under location.

You may set it in server level or inside "location ~ \.php$".
ustclucene (Guest)
on 2008-11-22 18:29
(Received via mailing list)
how to forbid using ip to visite my website  thanks
John M. (Guest)
on 2008-11-22 18:49
(Received via mailing list)
ustclucene wrote:
> how to forbid using ip to visite my website  thanks
>
>
>
Take a look at the NginxHttpAccessModule:

http://wiki.codemongers.com/NginxHttpAccessModule?...)
Calomel (Guest)
on 2008-11-22 20:39
(Received via mailing list)
One way is with an "if" statement.

## Only requests to our Host are allowed
      if ($host !~ ^(mydomain\.com|www\.mydomain\.com)$) {
         return 444;
      }


Nginx "how to" Fast, Secure and Efficient Web Server (nginx.conf)
https://calomel.org/nginx.html

--
  Calomel @ https://calomel.org
  Open Source Research and Reference
Igor S. (Guest)
on 2008-11-22 20:53
(Received via mailing list)
On Sat, Nov 22, 2008 at 01:29:09PM -0500, Calomel wrote:

> One way is with an "if" statement.
>
> ## Only requests to our Host are allowed
>       if ($host !~ ^(mydomain\.com|www\.mydomain\.com)$) {
>          return 444;
>       }

No, this is the worst way.
The right one is:

     server {
         server_name  _;  #default
         return 444;
     }

     server {
         server_name  mydomain.com
                      www.mydomain.com

                      # you may also
                      1.1.1.1 # allow IP-address
                      ""      # allow access without "Host" header,
0.7.11+

                      ;
         ...
     }
John M. (Guest)
on 2008-11-24 14:39
(Received via mailing list)
ustclucene wrote:
> how to forbid using ip to visite my website  thanks
>
>
>
Perhaps you need to explain a little more clearly what you mean, because
you have had two different types of answer, depending on the
interpretation of the question:

1. I assumed you meant how to ban certain IP addresses from accessing
your website

2. Others assumed you meant how to prevent someone attempting to access
your website using the IP address instead of the hostname

Which do you mean?
ustclucene (Guest)
on 2008-11-24 16:00
(Received via mailing list)
thank you, ok, I mean I want to prevent someone attempting to access
your website using the IP address instead of the hostname .

I use the Igor S. the way. It works well.
John M. 写道:
This topic is locked and can not be replied to.