2014-07-14 2 views
0

안녕하세요 mod_rewrite를 올바르게 설정하려고하는데 Lighttpd에 아무 문제가 없었지만 스왑도 nginx로 바꾸고 싶었습니다.Nginx Mod_Rewrite

location /highscores { 
    rewrite ^/highscores /?page=highscores last; 
} 
location /highscores/ { 
    rewrite ^/highscores/(.*)/(.*)$ /?page=highscores&list=$1&page=$2 last; 
} 

문제는 당신과 같은 방향을 세우면/최고 기록/끝 /와 오류 404가, 당신은/최고 기록을하려고하면/예를 들어이뿐만 아니라 404이지만,/최고 기록/예/아무도이 문제를 해결할 수 있습니까?

Google에서 해결책을 찾을 수 있습니다.

구성

server { 
     listen 80; 
    server_name example.com; 
    root /usr/share/nginx/www/example.com; 
    include /etc/nginx/include.d/all-common; 
    include /etc/nginx/include.d/example.com; 
} 

모든 일반적인

index index.php index.html index.htm; 
    try_files $uri $uri/ /index.html; 
location/{ 
    try_files $uri $uri/ = /; 
} 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    location ~ \.php$ { 
      try_files $uri =404; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 

    } 

example.com include.d에서 내가 최고

+0

Regexp'^/highscores /(.*)$'는'/ highscores /'나'/ highscores/example'과 일치하지 않으므로이 다시 쓰기가 적용되지 않습니다. 다시 쓰는 것은 무엇을 기대합니까? –

+0

또한 궁금합니다. 왜 두 페이지의 인수가 필요합니까? –

+0

하나만 있으면되지만 전혀 작동하지 않습니다. example.com/highscores 404 example.com/highscores/ 404 example.com/highscores/example가 아니라 그것을해야에서 작동하고 보여줍니다, 잘못 PARM의 목록을 보여줍니다 = $ (1) – WinterTime

답변

0

에 붙여 넣은 코드의 나머지 부분을 나는 같은 짓습니다 경로, 그래서 당신이 어떻게 느끼는지 꽤 명확하게 볼 수 있습니다. :)

것은이 프로젝트를 인출하고 설치 테스트하십시오 https://github.com/TeXXaS/nginx-configs

요점은 : 당신이 무슨 일이 일어나고 있는지 볼 수 있습니다

error_log /var/log/nginx/testing-rewrite-error.log debug; 
rewrite_log on; 

그 방법을.

Nginx에는 내부 리디렉션과 같은 것이 있습니다. 따라서 index 또는 rewrite을 터치하면 새 URL이 다시 처리된다는 의미입니다. 그 git repo를 들여다 보면 - 부분적으로 재 작성을위한 제품 솔루션이 있습니다. 즉 example.com/products/는 하나의 스크립트로 이어지고 example.com/product/the_product는 다른 위치로 이동합니다.