Nginx(Openresty) 프록시, 정적 파일에 사용자 정의 헤더 추가

Nginx(Openresty) 프록시, 정적 파일에 사용자 정의 헤더 추가

정적 파일에 헤더를 추가하려고 하는데 어떻게 해야 제대로 할 수 있나요?

중첩을 시도했지만 작동하지 않았습니다.

server {


    location / {
        proxy_pass http://apache.backend.local/;
        proxy_no_cache $http_pragma $http_authorization;

        proxy_cache radish_cache;
        proxy_cache_bypass $http_cache_control;
        add_header X-Proxy-Cache $upstream_cache_status;

        proxy_redirect          off;

        proxy_pass_header Set-Cookie;

        proxy_ignore_headers Cache-Control Expires;

        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_set_header X-Forwarded-Host   $host;
        proxy_set_header X-Forwarded-Port   $server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header Accept-Encoding '';
        proxy_set_header Connection '';
        proxy_set_header Referer $http_referer;
        proxy_set_header Cookie $http_cookie;

        proxy_hide_header X-Powered-By;

        proxy_connect_timeout 59s;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers 16 32k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 64k;

        location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
            gzip_static off;
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
        }

        location ~* \.(js)$ {
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 10d;
            break;
        }

        location ~* \.(css)$ {
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 10d;
            break;
        }
    }

}

또한 중첩하지 않고 각 위치에 프록시 구성을 포함하려고 하면 이 오류가 발생합니다.

"proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except"

최신 openresty를 사용하고 있습니다.

답변1

/명령문 의 뒤에는 proxy_pass오류 메시지에 언급된 "URI 부분"이 있습니다.

구성 파일에는 다음이 포함됩니다.

location / {
    proxy_pass http://apache.backend.local/;
    ...
}

/(에서 location)를 /(문에서 )로 번역하는 것은 proxy_pass의미가 없습니다. 따라서 "URI 부분"은 불필요하므로 제거해야 합니다.

proxy_pass다양한 구현을 시도했을 때정규식 location블록, "URI 부분"이 오류 메시지를 트리거했습니다. 그러나 URI 변환을 수행할 필요가 없으므로 proxy_pass후행 /.

보다이 문서자세한 내용은.

관련 정보