Results 1 to 5 of 5
  1. #1

    nginx with php-fpm troubles

    Hello, we're using php-fpm and have trouble getting the scripts to work if we change the 'root' value in nginx.conf.

    location ~ \.php$ {
    root /usr/share/nginx/html ;


    If we change that root to point to other directory, even if it's /usr/share/nginx/html/crap, it wouldn't work. The directory exists of course. It's like it can read the file in that directory, but not execute it. I've checked all file permissions. Anyone has any idea?

  2. #2
    Join Date
    Aug 2002
    Location
    Milton Keynes
    Posts
    354
    Why are you changing the document root just for PHP? A request will come in, be matched against a .php file, at that point all the variables will be correct to pass onto php-fpm, but then you change the root and mess it up!

    Can you give a better example of your directory layout & existing nginx config?

  3. #3
    Join Date
    Jul 2009
    Posts
    189
    Luckily I am just searching how to setup NGINX with fpm ... check this site out => http://interfacelab.com/nginx-php-fpm-apc-awesome/

  4. #4
    Join Date
    Aug 2002
    Location
    Milton Keynes
    Posts
    354
    I'm using the following as my `fastcgi_params` file:
    Code:
    set $script     $uri;
    set $path_info  "";
    
    if ($uri ~ "^(.+\.php)(/.+)") {
            set $script     $1;
            set $path_info  $2;
    }
    
    fastcgi_index  index.php;
    fastcgi_param SERVER_NAME $http_host;
    
    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_FILENAME     $document_root$script;
    fastcgi_param  SCRIPT_NAME        $script;
    fastcgi_param  PATH_INFO          $path_info;
    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;
    Then in the specific vhost:
    Code:
    location ~ \.php($|/) {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_ignore_client_abort on;
    }
    I wouldn't bother having a new document `root` just for PHP files unless you're doing anything specifically weird, in my case I set the document `root` once at the `server` level and perform internal rewrites for any relocation or different URL schemes.

    e.g.
    Code:
    if (-f $request_filename) {
        break;
    }
    
    if (!-e $request_filename) {
        rewrite ^(.+)$ /index.php$1 last;
        break;
    }

  5. #5
    Why are you changing the document root just for PHP? A request will come in, be matched against a .php file, at that point all the variables will be correct to pass onto php-fpm, but then you change the root and mess it up!
    I would like to change the root not just for PHP, but for all other file types as well. Basically I would like to use a user's home directory (example: /home/usera/, instead of /usr/share/nginx/html because then once the user ftp in, he'll be in the correct directory (home dir) to upload his files.

Similar Threads

  1. How to install PHP-FPM and PHP on Ubuntu?
    By Sanoj_ in forum Hosting Software and Control Panels
    Replies: 0
    Last Post: 03-15-2010, 12:09 PM
  2. Replies: 2
    Last Post: 01-15-2010, 02:01 PM
  3. Apache vs Nginx (mod_php VS php-fpm)
    By bostjan in forum Hosting Security and Technology
    Replies: 7
    Last Post: 06-25-2009, 07:19 AM
  4. nginx and php issues
    By djsmokin in forum Hosting Security and Technology
    Replies: 10
    Last Post: 03-27-2009, 02:16 PM
  5. nginx quirk on running encrypted script? (running with php-fpm)
    By Darvil in forum Hosting Security and Technology
    Replies: 20
    Last Post: 10-13-2008, 06:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •