
나는 가지고있다두 개의 디렉토리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;
}