2016-07-23 2 views
0

나는 나의 가상 호스트에 대한이 구성을 가지고 :nginx conf의 추가 위치가 404 코드를 반환하는 이유는 무엇입니까?

server { 
    listen 80; 
    root /var/www/home; 
    access_log /var/www/home/access.log; 
    error_log /var/www/home/error.log; 

    index index.php index.html index.htm; 

    server_name home; 

    location/{ 
     try_files $uri $uri/ /index.php?$args; #if doesn't exist, send it to index.php 
    } 

    error_page 404 /404.html; 
    error_page 500 502 503 504 /50x.html; 

    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/run/php/php-fpm.sock; 

     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param PHP_VALUE "error_log=/var/www/home/php_errors.log"; 
    } 

    location ~* /Admin { 
     allow 127.0.0.1; 
     deny all; 
    } 
} 

내가 페이지에 액세스하려고/관리자의 nginx는 PHP에 의해 생성 된 성공적인 HTML 콘텐츠와 404 코드를 반환합니다./Admin을 사용하여 위치를 삭제하면 모든 것이 잘됩니다.

추가 위치 문제는 어떻게 얻을 수 있습니까?

답변

1

다양한 위치 블록의 우선 순위를 이해하려면 this document을 읽어야합니다.

그래서, 당신은 우선 할 수 있도록 location ~ \.php$ 블록 위의 정규식 위치를 배치, 또는 그것을 바꿀 수 : 어떤 정규식 위치보다 우선 접두사 위치

location ^~ /Admin { ... } 

(이 파일 내의 순서가 부적절한 경우).

두 번째 문제점은 allow 127.0.0.1 문의 목적입니다. 1273.01에 클라이언트의 /Admin 접두사가있는 .php 개의 파일을 실행하려고합니까?

관리자 위치 블록에 .php 개의 파일을 실행할 수있는 코드가 없습니다. 의도는 /Admin 접두사 .php 파일을 실행하는 경우, 당신은 시도 할 수 :

location ~ \.php$ { 
    try_files $uri =404; 
    fastcgi_pass unix:/run/php/php-fpm.sock; 

    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param PHP_VALUE "error_log=/var/www/home/php_errors.log"; 
} 

location ^~ /Admin { 
    allow 127.0.0.1; 
    deny all; 

    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/run/php/php-fpm.sock; 

     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 

는 별도의 파일에 공통의 문을 이동 include 지시어를 사용할 수 있습니다.

how nginx processes a request을 참조하십시오.