2012-06-12 4 views
0

나는 여기서 조금 잃어 버렸습니다. 내의 nginx의 conf 파일에서 나는이 상태 규칙을 원하는 :NGINX 설정 정규식 문제

if $request_uri does not contain following words (css|images|js) then rewrite all to /index.php 

이 내가 가진 것입니다,하지만이 작동하지 않습니다

if ($request_uri ~ !(images|css|js)) { 
    rewrite $ /index.php; 
} 

내가 생각하는 정규 표현식을 일치되지 않는 이유는 무엇입니까?

편집 :이 솔루션

if ($request_uri !~* (images|css|js)) { 
    rewrite $ /index.php; 
} 

답변

1
  1. IfIsEvil 비싼에게 있습니다.
  2. 대신 양 논리를 사용하십시오.

모든 정적 컨텐츠를 디렉토리에 넣는 것이 좋습니다.

-static 
|--images 
|--css 
|--js 


server { 
    server_name www.foo.com; 
    root /your_nginx_root/; 

    location/{ 
    index index.php; 
    } 

    location /static { 
    add_header Cache_control "public"; 
    expires max; 
    } 

    error_page 301 302 400 401 402 403 404 405  /index.php; 
    error_page 406 408 409 410 411 412 413 414  /index.php; 
    error_page 415 416 495 496 497 500 501 502  /index.php; 
    error_page 503 504 507       /index.php; 
} 


* 편집 : * 내가 아는이

if ($request_uri !~* (images|css|js)) { 
    rewrite $ /index.php; 
} 
+0

, 내 정적 파일이 정적 폴더에 시도하지만, 결국 정규식 일치 이런 식으로 뭔가를 (해야 할 것이다 JS | css | sitemap | images | fonts | media | uploads | pdf | callbacks) – Bundy

+0

이 접근법을 사용하는 것이 더 나은 디렉토리에 있다면, 그렇지 않다면 조건을 점검해보십시오. –

+0

@Bundy가 작동하는지 확인하십시오. 여기서 테스트 할 수 없습니다. –