2017-01-14 5 views
1
server { 

    server_name mediaserver.localdomain; 
    listen 80; 
    index index.php index.htm index.html; 
    root /var/www/html/Organizr; 
    location =/{ 
     root /var/www/html/Organizr; 
    } 
    location /homelab { 
     alias /opt/homelab/; 
    } 
    location ~ /\.git { 

     deny all; 
    } 
    location ~ \.php$ { 

    include snippets/fastcgi-php.conf; 
    fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 

} 

Die Include-Schnipsel/fastcgi-php.com; =nginx Konfigurationsprobleme (root/alias)

# 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; 

Das ist meine Konfiguration und für das Leben von mir kann ich es nicht zur Arbeit bekommen.

Meine Erwartung ist, die http haben: // mediaserver.localdomain/zum "/var/www/html/Organizr/index.php" gehen

Und wenn ich gehen, um http: // Mediaserver .localdomain/homelab/sie zieht die "/opt/homelab/index.php"

Aber nur die http: // mediaserver.localdomain/funktioniert nicht/homelab/

ich meine google-Admin-Techniken erschöpft und die nginx-Dokumentationsseiten zu Alias- und Root-Definitionen.

Vielen Dank im Voraus.

FYI (i setzen die Räume in den Links absichtlich von Auto-Links loszuwerden)

Antwort

1

Sie haben zwei Wurzeln, aus denen Sie PHP-Dateien ausführen müssen, das heißt, Sie müssen zwei getrennte Standorte mit Ihrer fastcgi_pass Richtlinie.

server { 
    server_name mediaserver.localdomain; 
    listen 80; 
    index index.php index.htm index.html; 

    root /var/www/html/Organizr; 

    location/{ 
     try_files $uri $uri/ =404; 
    } 
    location ~ /\.git { 
     deny all; 
    } 
    location ~ \.php$ { 
     try_files $uri =404; 
     include snippets/fastcgi-php.conf; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 

    location ^~ /homelab { 
     root /opt; 
     try_files $uri $uri/ =404; 

     location ~ \.php$ { 
      try_files $uri =404; 
      include snippets/fastcgi-php.conf; 
      fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     } 
    } 
} 

Der location / Block die root von dem äußeren Block erbt, muss sie nicht wiederholt werden.

Der erste location ~ \.php$ Block verarbeitet alle .php URI, die nicht mit /homelab beginnt.

Der Block location ^~ /homelab ist eine Präfixposition, die Vorrang vor anderen regulären Ausdruckspositionen auf derselben Ebene hat. Details siehe this document.

Die verschachtelte location ~ \.php$ Block ist für die Verarbeitung .php URIs unter /homelab die in /opt/homelab befinden.

Ich habe ein paar try_files directives hinzugefügt, die auch die issue of passing uncontrolled requests to PHP adressiert.

+0

Danke Richard; Die try_files sind doppelt vorhanden, weil die Snippets folgendes haben: # Überprüfen Sie, ob das PHP-Skript existiert, bevor Sie es übergeben try_files $ fastcgi_script_name = 404; – Loopback

+0

Sobald ich die try_files entfernt habe funktioniert alles wie angekündigt .. danke für die tolle Erklärung! – Loopback