Noob needs help with alias locations and php

Hi all,

Been going in circles for the third day now.

The server handles files and php scripts as long as they are at or
beneath the document root. Here are the two problems I haven’t been
able to figure out:
Directory index of … is forbidden
Can’t get to docs not beneath the document_root.

Example of places I want to go:

non-root targets: as:
/home/mike/Movies/index.html /movies/index.html 200
/home/mike/Movies/index.php /movies/index.php “File not found.”
/home/mike/Movies/1/index.html /movies/1/index.html 404
/home/mike/Movies/1/index.php /movies/1/index.php “File not found.”

File not found : “Primary script unknown”;
404 : the log shows the correct GET path;
A lot of my experiments end up with 301 : endless redirects;

http {
index index.html index.php;

server {
listen 80;
server_name localhost lo;
root /var/www/sites/localhost/www;

location / {
try_files $uri $uri/ /index.html /index.php;
}

location /movies {
alias /home/mike/Movies/;
}

location ~ .php$ {
root /var/www/sites/localhost/www;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

If I can get past these hurdles I’ll probably (hopefully) be able to
figure most of the rest of this stuff out.

Tips, pointers appreciated. Helper?

Thanks,
Mike Wright

On Wed, May 27, 2015 at 09:49:27PM -0700, Mike Wright wrote:

Hi there,

In general in nginx, one request is handled in one location. Only the
configuration in, or inherited into, that location, matters.

It you use rewrite-module directives, things are a bit more complicated.

There is lots at nginx documentation; it may be hard to find the
one piece of information you want, but it is probably there somewhere.

The server handles files and php scripts as long as they are at or
beneath the document root. Here are the two problems I haven’t been
able to figure out:
Directory index of … is forbidden

What one request do you make that leads to that problem?

What is the one location that handles that request?

Can't get to docs not beneath the document_root.

Same questions.

A lot of my experiments end up with 301 : endless redirects;
location / {
try_files $uri $uri/ /index.html /index.php;
}

The request “/movies/index.html” will be handled in this location:

location /movies {
alias /home/mike/Movies/;
}

(Usually, it is good if the number of /s at the end of “alias” and and
the end of “location” are the same.)

The request “/movies/index.php” will be handled in this location:

location ~ .php$ {
root /var/www/sites/localhost/www;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

Enable more logging; or “tcpdump”, to see what nginx sends to your
fastcgi
server. “/movies/index.php” is unlikely to be correctly handled here.

Good luck with it,

f

Francis D. [email protected]