2012-08-24 5 views
3

문서를 읽었으며 예제를 스캔했는데 왜 작동하지 않는지 알 수 없습니다. 나는 완전히 nginx에 익숙하다. 그래서 이것이 어리석은 간단한 대답이라면, 나에게 쉽게 가라.Nginx가 위치 지시어를 무시합니까?

user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
     worker_connections 768; 
     # multi_accept on; 
} 

http { 

     ## 
     # Basic Settings 
     ## 

     sendfile on; 
     tcp_nopush on; 
     tcp_nodelay on; 
     keepalive_timeout 65; 
     types_hash_max_size 2048; 
     # server_tokens off; 

     # server_names_hash_bucket_size 64; 
     # server_name_in_redirect off; 

     include /etc/nginx/mime.types; 
     default_type application/octet-stream; 

     ## 
     # Logging Settings 
     ## 

     access_log /var/log/nginx/access.log; 
     error_log /var/log/nginx/error.log; 

     ## 
     # Gzip Settings 
     ## 

     gzip on; 
     gzip_disable "msie6"; 

     # gzip_vary on; 
     # gzip_proxied any; 
     # gzip_comp_level 6; 
     # gzip_buffers 16 8k; 
     # gzip_http_version 1.1; 
     # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

     ## 
     # Virtual Host Configs 
     ## 

     #include /etc/nginx/conf.d/*.conf; 
     #include /etc/nginx/sites-enabled/*; 

    server { 
       listen  80; 
       server_name localhost domain.com; 

       root /home/TMlabs/server_files; 
       index index.html index.htm; 

       location = /othersite { 
        root /home/TMlabs/server_files/location2; 
        index index.html index.htm; 
       } 

       location/{ 
        root /home/TMlabs/server_files/location1; 
        index index.html index.htm; 
       } 

     } 

더 많이 포함해야한다면 알려 주시기 바랍니다. 전체 nginx.conf를 덤프합니다. 그래도 꽤 기본입니다.

내가 달성하고자하는 것은 domain.com을/(작동 중) 위치에 지정된 루트에 매핑하고 domain.com/othersite를 해당 지시문에 지정된 루트에 매핑하는 것입니다. 어떤 이유로 든/home/TMlabs/server_files/location2 폴더의 index.html 파일보다는 domain.com/othersite를 탐색 할 때 /home/TMlabs/server_files/location1/index.html 문서를 반환합니다. 나는 equals를 제거하고 다른 연산자를 사용하여 일치를 시도했지만 아무 것도 작동하지 않는 것 같습니다. 아마도 내가 오해하고있는이 기본 요소에 익숙하지 않을 수도 있습니다. 나는 또한 regexp에서 빨아. 누구든지 계몽에 관심이 있습니까?

편집 : 내 생각에 실제로는 내 지시문을 완전히 무시하고 단순히/usr/share/nginx/www를 문서 루트로 사용하고 있습니다. 나는이 설정이 어디에도 보이지 않는다. 나는 무엇을 놓치고 있습니까?

+0

내부의 default_type 지시어를 사용할 수 있습니다. 더 자세하게 게시하십시오. – Dayo

+0

나머지를 추가했습니다. 저는 템플릿에서 일하고 있습니다. 나머지는 템플릿입니다. 위에서 게시 한 전체 구성의 –

+0

에 http 블록의 닫는 괄호가 없습니다. 또한 색인 지시문이 상속되므로 각 위치 블록에서 반복하지 않아도됩니다. 그리고/othersite는 특정/othersite url 만 일치한다는 것을 의미합니다. 아마도 당신이 원하는 것이 아닌 어떤 서브 페이지가 아닙니다. – cobaco

답변

2

= 접두어가 지정 위치가 정확히 요청 된 URL과 일치해야 함을 의미한다. 오류 로그를 보면 Nginx가 [...]/location2/otherside이 아닌 [...]/location2/index.{html,htm}이 아닌 파일을 제공하려고 시도합니다. (전체 경로는 간략하게하기 위해 생략 함)

index 지시어는 정확한 일치 위치의 noop입니다.

는이 문제를 해결하려면, 당신은 otherside에 파일 이름을 변경하고이 구성

location = /otherside { 
    root /home/TMlabs/server_files/location2; 
} 

이 있거나 alias 지시어를 사용할 수 있습니다

location = /otherside { 
    alias [...]/location2/index.html; 
} 

PS : Nginx에가의 Content-Type을 파악하려고합니다 URL의 확장에 의한 응답. /otherside에는 확장자가 없으므로 application/octet-stream을 사용하여 브라우저가 try and download the content이됩니다.

은 당신이 중 하나는 .html 확장자를 포함, 또는 그 결과를 얻을 수 있습니다에가는 다른 뭔가가 있어야 당신이 당신의 예를 들어 설정을 과도하게 단순화 한 것 같아요 location

default_type "text/html"; 
+0

설명해 주셔서 감사합니다!그리고 여분의 맛있는 가벼운 음식. 내 문제는 다소 단순한 것으로 끝나고 error.log 파일을 찾았습니다. (파일 경로 맹 글링.) 그러나이 점들은 나의 초기 질문에 답하고 매우 도움이된다! 고마운 Dan, 하하! –

0

하여 트릭을 할해야 다음

server { 
     listen  80; 
     server_name localhost domain.com; 

     root /home/TMlabs/server_files; 
     index index.html index.htm; 

     location/{ try_files location1/$uri location1/$uri/; } 
     location /othersite { try_files location2/$uri location2/$uri/; } 
} 
+0

이것이 작동하지 않습니다./ –

관련 문제