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.
C3ab146b8cf153e371e60a6f288f7188?d=identicon&s=25 Joe Shang (Guest)
on 2008-11-21 18: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;
C3ab146b8cf153e371e60a6f288f7188?d=identicon&s=25 Joe Shang (Guest)
on 2008-11-21 18:02
(Received via mailing list)
Figured it out.

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

Joe
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2008-11-21 18:14
(Received via mailing list)
Hello!

On Fri, Nov 21, 2008 at 10:34:44AM -0600, Joe Shang 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 Dounin
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2008-11-21 18:51
(Received via mailing list)
On Fri, Nov 21, 2008 at 10:50:52AM -0600, Joe Shang 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$".
9573b75abe8f06866ef73cff28185535?d=identicon&s=25 ustclucene (Guest)
on 2008-11-22 17:29
(Received via mailing list)
how to forbid using ip to visite my website  thanks
2107d4e4b544f904194507258a40cac1?d=identicon&s=25 John Moore (Guest)
on 2008-11-22 17: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?...)
Ac43602b48fded2c3ba2464ed13bfd59?d=identicon&s=25 Calomel (Guest)
on 2008-11-22 19: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
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2008-11-22 19: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+

                      ;
         ...
     }
2107d4e4b544f904194507258a40cac1?d=identicon&s=25 John Moore (Guest)
on 2008-11-24 13: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?
9573b75abe8f06866ef73cff28185535?d=identicon&s=25 ustclucene (Guest)
on 2008-11-24 15: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 Sysoev the way. It works well.
John Moore 写道:
This topic is locked and can not be replied to.