2014-04-13 1 views
1

현재 모든 URL을 example.com/page.html에서 example.com/page.html로 변경하기 위해 다음 설정 파일을 사용하고 있습니다. Page.html은 더 이상 SEO 이유로 액세스 할 수 없어야합니다. 매우 간단한 리디렉션이어야합니다. 검색 후 다음 코드를 발견했습니다.Nginx에서 static .html 엔딩을 제거하고 리디렉션하는 방법은 무엇입니까?

server { 

     listen myip8:8080; 
     root /mydir; 
     index index.html index.htm; 
     server_name example.com; 

# example.com/index gets redirected to example.com/ 

location ~* ^(.*)/index$ { 
    return 301 $scheme://$host$1/; 
} 

# example.com/foo/ loads example.com/foo/index.html 

location ~* ^(.*)/$ { 
    try_files $1/index.html @backend; 
} 

# example.com/a.html gets redirected to example.com/a 

location ~* \.html$ { 
    rewrite ^(.+)\.html$ $scheme://$host$1 permanent; 
} 

# anything else not processed by the above rules: 
# * example.com/a will load example.com/a.html 
# * or if that fails, example.com/a/index.html 

location/{ 
    try_files $uri.html $uri/index.html @backend; 
} 

# default handler 
# * return error or redirect to base index.html page, etc. 

location @backend { 
    return 404; 
} 

그러나 문제가 있습니다. 모든 정적 자산을 찾을 수 없습니다. CSS, JS, 등등은 단지 404 오류를 제공합니다.

해당 코드가 404를 유발할 수있는 것은 무엇입니까?

또한 서버 설정에주의해야합니다. 두 개의 분리 된 VPS가 있습니다. 광택과 Nginx. Varnish 서버는 Nginx에 요청을 프록시합니다. 그게 무슨 상관이 있는지 나는 잘 모르겠다. 마지막으로 코드를 발견 한 원본 스레드는 다음과 같습니다. redirect /foo.html to /foo but not/to /index in nginx OP 용으로 작동하는 것처럼 보였지만 제대로 작동하지 않습니다.

답변

2

yea 예를 들어 서버가 을 시도하기 때문에 자체적으로 $uri에 액세스하려하지 않으므로 이는 매우 논리적입니다.

이미 위의 html 사례를 처리 했으므로 $uri을 최우선으로 추가해야합니다.

+0

고쳐주었습니다. 나는 그런 작은 것이 될 줄 알았습니다. 도움에 정말 감사드립니다. – Nilnoc