2014-04-23 4 views
0

내가 원하는 방식으로 내 nginx 설정을 얻는 데 문제가 있습니다. 나는/vagrant/frontend/www에 위치한 사이트 example.localhost를 가지고있다.하위 폴더에 nginx 사이트

server { 
    listen 80; 
    server_name example.localhost; 

    root /vagrant/frontend/www; 
    index index.php; 

    location/{ 
     try_files $uri $uri/ /index.php$is_args$args; 
    } 

    location ~ .*\.php$ { 
     include /etc/nginx/fastcgi.conf; 
     try_files $uri = 404; 
     fastcgi_pass 127.0.0.1:9000; 
    } 
} 

을하지만 그때 나는 주소 example.localhost/관리자에게/방랑/백엔드/www가에있는 관리자 사이트를 추가 할 : 노력이에 대한 나의 구성은 다음과 같습니다.

location /admin { 
    root /vagrant/backend/www; 
} 

location ~ /admin/.+\.php$ { 
    include /etc/nginx/fastcgi.conf; 
    try_files $uri = 404; 
    fastcgi_pass 127.0.0.1:9000; 
} 

오류 로그는 다음과 같습니다 : 일이 잘못, 나는 this post에 따라, 아래의 설치를 찾을 수 없습니다 (404)을받을 때이다

2014/04/23 12:30:10 [error] 15459#0: *1 "/vagrant/backend/www/admin/index.php" is not found (2: No such file or directory), client: 192.168.56.1, server: example.localhost, request: "GET /admin/ HTTP/1.1", host: "example.localhost" 

내가 얻을 왜 내가 볼 404,하지만이 권리는 어떻게 얻을 수 있습니까? 어떤 도움을 많이 주시면 감사하겠습니다!

UPDATE는

나는이 내 관리자의 위치를 ​​변경 : 이제

location ~ /admin/.+\.php$ {...} 

/관리자를 example.localhost하는 전화 :

location /admin { 
    alias /vagrant/backend/www/; 
    try_files $uri $uri/ /index.php?$args; 

    location ~ \.php$ { 
     include /etc/nginx/fastcgi.conf; 
     fastcgi_pass 127.0.0.1:9000; 
    } 
} 

나는이 블록을 제거했다 올바른 처리되지만, 예를 들어 example.localhost/admin/site/index로 변경하면 프론트 엔드가 요청을 처리합니다./admin 위치가 일치하지 않는 것 같습니다 ... 어떤 생각입니까?

+0

여기서 실제 파일은 무엇입니까? –

+0

파일은 다음 위치에 있습니다. /vagrant/backend/www/index.php – skukje

답변

0
server { 
    listen 80; 
    server_name example.localhost; 

    root /vagrant/frontend/www; 
    index index.php; 

    location/{ 
      try_files $uri $uri/ /index.php?$args; 

      location ~ \.php$ { 
        include fastcgi.conf; 
      } 
    } 

    location /admin { 
      return 301 /admin/; 
    } 

    location /admin/ { 
      alias /vagrant/backend/www/; 
      try_files $uri $uri/ @handler; 

      location ~ \.php$ { 
        include fastcgi.conf; 
      } 
    } 

    location @handler { 
      rewrite//admin/index.php?$args; 
    } 
} 
0

location 블록은 완전히 독립적입니다. 귀하의 요청은 마지막으로 location 블록으로 끝나고 첫 번째 블록의 root 지시문을 볼 수 없습니다. 두 번째 블록에 root 지시어를 넣습니다. "/vagrant/backend/www/admin/index.php"가 발견되지 않는 경우

location ~ /admin/.+\.php$ { 
    root /vagrant/backend/www; 
    include /etc/nginx/fastcgi.conf; 
    try_files $uri = 404; 
    fastcgi_pass 127.0.0.1:9000; 
} 
+0

답장을 보내 주셔서 감사합니다. 나는 당신의 제안을 시도했지만, 이제는 프론트 엔드로 라우트되고, 결국 예외로 끝납니다. 그것은 내게 위치 블록이 일치하지 않는 것처럼 보입니다. 따라서 "기본"루트가 사용됩니다 ... – skukje

+0

다른 PHP 파일의 위치 블록 앞에이 블록을 배치하십시오. regexp locatin 블록에 대해서는 nginx가 –

+0

과 일치하는 것을 먼저 사용했지만, 불행히도 아무런 차이가 없었습니다. 가장 정확한 히트를 제공하는 정규 표현식이 선택되므로 위치 블록의 위치는 중요하지 않습니다. – skukje