Nginx not sending DOCUMENT_ROOT to PHP?

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:

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;

Figured it out.

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

Joe

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.

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$”.

how to forbid using ip to visite my website thanks

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

ustclucene wrote:

how to forbid using ip to visite my website thanks

Take a look at the NginxHttpAccessModule:

http://wiki.codemongers.com/NginxHttpAccessModule?highlight=(access)

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?

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+

                  ;
     ...
 }

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. 写道: