
私は持っている2つのディレクトリ私のサーバーではdirectory1
、その他のディレクトリ内側にdirectory2
は単一ファイル index.php
。
index.php
私は私のにアクセスしたいhttp://サーバー/(/var/www/directory2/index.php
)また、すべてのディレクトリを内部で利用できるようにするにはdirectory1
、http://サーバー/テスト(var/www/directory1/test
) 例えば。
その設定で試してみましたが、index.php
ファイルにアクセスできません:
server {
server_name server;
index index.php index.html index.htm;
access_log /var/log/nginx/server.access.log;
error_log /var/log/nginx/server.error.log;
location / {
root /var/www/directory1;
}
location ~ ^/index.php$ {
root /var/www/directory2;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}
}
ご協力ありがとうございます!
答え1
私はこれを簡単にやります:
root /var/www/directory1;
location = / {
root /var/www/directory2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}