-1

I am trying to set up an alias so I can navigate to ww.*.com/dev/ and have it be serving files from out side of the root directory.

Things i've tried

  • ensured php block is in location block
  • tried replacing alias with root
  • tried commenting out include snippets/fastcgi-php.conf;
  • tried the suggested fix for try_files inside of nested blocks.

root - /var/www/nginx/www/a ailas - /var/www/nginx/www

my alias

  location /dev {
           alias /var/www/nginx/www;
               location ~ /([^/]+\.php)$ {
                   include snippets/fastcgi-php.conf;
                 # try_files /$1 =404;
                   fastcgi_split_path_info ^(.+\.php)(/.+)$;
                   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                  # fastcgi_index index.php;
                   include fastcgi_params;
               }
       }

snippets/fastcgi-php.conf

 # regex to split $uri to $fastcgi_script_name and $fastcgi_path
  fastcgi_split_path_info ^(.+\.php)(/.+)$;

   # Check that the PHP script exists before passing it
   try_files $fastcgi_script_name =404;

   # Bypass the fact that try_files resets $fastcgi_path_info
   # see: http://trac.nginx.org/nginx/ticket/321
   set $path_info $fastcgi_path_info;
   fastcgi_param PATH_INFO $path_info;

  fastcgi_index index.php;
   include fastcgi.conf;

fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  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  REQUEST_SCHEME     $scheme;
  fastcgi_param  HTTPS              $https if_not_empty;

  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;

any help will be appreciated

0

Try:

location ^~ /dev {
    alias /var/www/nginx/www;
    if (!-e $request_filename) { rewrite ^ /dev/index.php last; }

    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }

        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
        fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
    }
}

Use the ^~ modifier on the location block to avoid potential conflicts with other regular expression location blocks. See this document for details.

Avoid using try_files and alias together because of this long standing issue.

Most of your snippets/fastcgi-php.conf file is related to the use of pathinfo, which you do not appear to be using.

See this caution on the use of if.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.