>  기사  >  백엔드 개발  >  nginx-위치 패턴에 관한 몇 가지 질문

nginx-위치 패턴에 관한 몇 가지 질문

WBOY
WBOY원래의
2016-08-29 08:50:551218검색

많은 정보를 확인했지만 몇 가지 궁금한 점을 여전히 알 수 없습니다.

첫 번째 질문은 내 위치 구성이 다음과 같은 경우입니다.

<code>location /doc {
    alias /home/user/doc;
}
</code>

그러면 http://localhost/doc/a.html에 액세스하면 nginx는 실제로 /home/usr/doc/a.html을 읽습니다. http://localhost/docs/a.html 또는 심지어 http://localhost/docsioajsfopajowejfasd에 액세스하면 nginx는 실제로 어떤 파일을 읽으려고 할까요?

두 번째 질문입니다. 문서를 서버로 구성한 다음 역방향 프록시를 사용하는 경우입니다.

<code>server {
    listen 8000;
    server_name doc;
    root /home/user/doc;
    
    index index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}
</code>

메인 서버에서 다음과 같이 구성하세요.

<code>server {
    listen 80;
    ....
    location /doc {
        proxy_pass http://localhost:8000/;
    }
    }
</code>

이 구성에서 http://localhost/doc/에 액세스할 때 인덱스 파일이 정적 파일을 참조하면 정적 파일은 404이 되며, http://localhost/js/xxx.js을 추가하면 브라우저는 http://localhost/doc/js/xxx.js 대신 /을 얻으려고 시도합니다. 🎜 패턴이 >된 후

<code>location /doc/ {
            proxy_pass http://localhost:8000/;
        }
</code>

에는 문제가 없으나 첫 번째 질문의 위치 구성이라면 브라우저는 http://localhost/doc/js/xxx.js을 정확하게 찾아줍니다. 끝에 /를 추가하면 어떤 영향이 있나요? alias와 Proxy_pass의 결과가 다른 이유는 무엇입니까?

답글 내용:

많은 정보를 확인했는데 아직도 몇 가지 궁금한 점을 알 수 없습니다.

첫 번째 질문, 내 위치 구성이 다음과 같은 경우:

<code>location /doc {
    alias /home/user/doc;
}
</code>

그러면 http://localhost/doc/a.html에 액세스하면 nginx는 실제로 /home/usr/doc/a.html을 읽습니다. http://localhost/docs/a.html 또는 심지어 http://localhost/docsioajsfopajowejfasd에 액세스하면 nginx는 실제로 어떤 파일을 읽으려고 할까요?

두 번째 질문입니다. 문서를 서버로 구성한 다음 역방향 프록시를 사용하는 경우입니다.

<code>server {
    listen 8000;
    server_name doc;
    root /home/user/doc;
    
    index index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}
</code>

메인 서버에서 다음과 같이 구성하세요.

<code>server {
    listen 80;
    ....
    location /doc {
        proxy_pass http://localhost:8000/;
    }
    }
</code>

이 구성에서 http://localhost/doc/에 액세스할 때 인덱스 파일이 정적 파일을 참조하면 정적 파일은 404이 되며, http://localhost/js/xxx.js을 추가하면 브라우저는 http://localhost/doc/js/xxx.js 대신 /을 얻으려고 시도합니다. 🎜 패턴이 >된 후

<code>location /doc/ {
            proxy_pass http://localhost:8000/;
        }
</code>

에는 문제가 없으나 첫 번째 질문의 위치 구성이라면 브라우저는 http://localhost/doc/js/xxx.js을 정확하게 찾아줍니다. 끝에 /를 추가하면 어떤 영향이 있나요? alias와 Proxy_pass의 결과가 다른 이유는 무엇입니까?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.