2017-01-14 14 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; 
    } 

} 

include snippets/fastcgi-php.com; =nginx設定の問題(ルート/エイリアス)

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

これは私の設定であり、私の人生にとってはうまく動作しません。

私の期待は、HTTPを持っていることです://はmediaserver.localdomain/"/var/www/html/Organizr/index.php" に

に行くと私は、httpに行くとき:// MediaServerの.localdomain/homelabは/それは "/opt/homelab/index.php"

しかし、唯一のhttpを引っ張る:// mediaserver.localdomain /作品ではない/ homelab /私はGoogleの管理技術を使い果たしてしまった

エイリアスとルート定義に関するnginxのドキュメントページ。

ありがとうございます。 FYI

(私は自動リンクを取り除くために、意図的にリンクにスペースを入れる)

答えて

1

あなたはあなたがあなたのfastcgi_passディレクティブを持つ2つの別々の場所を必要とすることを意味する、PHPファイルを実行する必要があり、そこから2つの根を持っています。

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

location /ブロックは外側のブロックからrootを継承し、それを繰り返す必要はありません。

最初のlocation ~ \.php$ブロックは、/homelabで始まらない任意の.php URIを処理します。

ブロックは、同じレベルの他の正規表現の場所よりも優先されるプレフィックスの場所です。詳細はthis documentを参照してください。

ネストされたlocation ~ \.php$ブロックは、/opt/homelabにある/homelab以下のURIを処理する責任があります。

にも対応する数少なくtry_files directivesを追加しました。

+0

ありがとうございました。 try_filesは複製されています。スニペットには次のようなものがあります。#PHPスクリプトが存在することを確認してから渡してください。 try_files $ fastcgi_script_name = 404; – Loopback

+0

try_filesを削除すると、すべてが広告として機能します。大きな説明に感謝します! – Loopback