2016-06-02 2 views
1

저는 아마추어 프런트 엔드 웹 개발자이며 최근에 우분투 서버를 구입하여 일부 백엔드 개발시 손을 잡았습니다. php5-fpm을 사용하여 별명이 지정된 위치 블록에서 PHP 파일을 제공하는 방법을 알아 내려고합니다. 404 - 페이지를 찾을 수 없습니다. 오류가 발생합니다. 나는 행운을 빌어 여기에서 찾을 수있는 제안 된 모든 해결책을 시도했다. 나는 아직 초보자이므로 빠른 ELI5와 나머지 모든 conf 파일의 포인터를 좋아할 것입니다. 그래서 나는 또한 뭔가를 배울 수 있습니다. 기본 루트 폴더가 플라스크 응용 프로그램을 실행 중이며 별칭이 지정된 위치를 사용하고있는 이유입니다.Nginx + php5-fpm = 404 별칭 위치에 오류가 있습니다.

내 가상 호스트 :

Nginx의 conf의 파일

server { 
listen 80; 
listen [::]:80; 
server_name www.example.com example.com; 

root /var/www/example; 
large_client_header_buffers 8 32k; 
access_log /var/www/example/logs/access.log; 
error_log /var/www/example/logs/error.log; 


location/{ 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $remote_addr; #$proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_pass http://app_test; 
    proxy_redirect off; 
} 


location /test_site { 
    alias /var/www/test_site; 
    index index.php index.html index.htm; 
    location ~ .php$ { 
       try_files $uri =404; 
       fastcgi_split_path_info ^(.+?\.php)(/.*)?$; 
       fastcgi_pass unix:127.0.0.1:9000; 
       fastcgi_index index.php; 
       include fastcgi_params; 
    } 
    } 

PHP5의 www.conf 파일

[www] 
... 
user = www-data 
group = www-data 


listen = 127.0.0.1:9000 
#listen = /tmp/php5-fpm.sock 

listen.owner = www-data 
listen.group = www-data 
listen.mode = 0660 
... 

내 fastcgi_params 파일은 기본값입니다. php와 nginx 로그를 모두 확인 했으므로 오류가 없습니다. 어떤 도움을 많이 주시면 감사하겠습니다!

답변

0

fastcgi을 사용하여 중첩 된 위치에서 작동하도록 alias을 얻는 것은 복잡합니다.

당신이 당신의 구성을 단순화하지 않은 이상 있다고 가정하면, test_site 위치는 alias를 사용할 필요가 없습니다 :

location /test_site { 
    root /var/www; 
    index index.php index.html index.htm; 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:127.0.0.1:9000; 
     include fastcgi_params; 
    } 
} 

이것은 alias 지시어를 제거하고 PHP 블록의 앨리어싱 문제를 해결한다.

참고 : location ~ \.php$ 블록의 정규식이 잘못되었습니다. fastcgi_split_path_infofastcgi_index 지시어는 필요하지 않습니다.

nginx 지시어는 documented here입니다.

관련 문제