Nginx는 단일 위치에 대한 리디렉션을 방지합니다.

Nginx는 단일 위치에 대한 리디렉션을 방지합니다.

https를 강제하는 리디렉션이 있습니다.

server {
    listen 80;

    server_name example.com;
    return 301 https://example.com$request_uri;
}

훌륭하게 작동하지만 http를 통해 단일 텍스트 파일을 조회할 수 있기를 원합니다.에코 모듈:

server {
    listen 80;

    location /ping {
        echo "http_pong";
    }

    server_name example.com;
    return 301 https://example.com$request_uri;
}

/ping불행히도 나는 대신 301 리디렉션을 받기 때문에 결코 접근할 수 없습니다 . 전역 리디렉션이 해당 단일 위치에 적용되지 않도록 하려면 어떻게 해야 합니까?

답변1

다음과 같이 아래에 리디렉션을 넣어보세요 location /.

server {
    listen 80;
    server_name example.com;

    location /ping {
        echo "http_pong";
    }

    location / {
        return 301 https://example.com$request_uri; 
    }
}

답변2

주의하세요 -"에코"는 더 이상 사용되지 않습니다.. "반환"을 사용하세요

location / {
  return 200 'http_pong';

}

관련 정보