docker上的Nginx-变化:缺少Accept-Encoding标头

时间:2018-08-06 06:30:00

标签: angular http docker nginx single-page-application

我正在从nginx提供一个静态网站,该网站在基于 nginx:alpine 基本映像的 docker 容器上运行。

我的DockerFile:

FROM nginx:alpine
COPY --from=angular-built app/dist/dayTwoApp /usr/share/nginx/html
COPY ./default.conf /etc/nginx/conf.d/default.conf

default.conf文件:

server {
   listen 80;

    gzip on;
    gzip_vary on;
    gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

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

    root /usr/share/nginx/html;
    index index.html index.htm;

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

在提供的html文件的响应中,我看到了variant:Accept-Encoding标头(请参见下文)。

但是由于某些原因,我在js和css响应中看不到标题。

(*)无效的相关参考文献:

详细回复:

html文件: enter image description here

js文件(也适用于CSS):

enter image description here

2 个答案:

答案 0 :(得分:1)

请尝试添加到您的nginx配置:

#include <setjmp.h>
typedef struct coro_context {
    int id;
    jmp_buf env;
    list_head list;
    jmp_buf waiter;
    long timeout;
    void *private;
    char stack[1]; /*c99 doesn't have flexible array members*/
} coro_context;

#define CORO_CONTEXT(name,size) \
    union { coro_context ctx; char buf[sizeof(coro_context)+size]; } name##_ctx__ = { { 0, {0},{0},{0}, 0, &name } }; \
    coro_context *name##_ctx = &name##_ctx__.ctx;

int my_name;

CORO_CONTEXT(my_name,32)

(只有“ text / html”类型的回复为always compressed。)

答案 1 :(得分:0)

在第二个示例中,Nginx返回HTTP响应代码304,该代码指示内容尚未从缓存副本中被修改。按照HTTP规范:

  

304响应必须不包含消息体,因此总是   由标题字段之后的第一个空行终止。

     

响应中必须包含以下标头字段:

  - Date, unless its omission is required by section 14.18.1
  - ETag and/or Content-Location, if the header would have been sent
    in a 200 response to the same request
  - Expires, Cache-Control, and/or Vary, if the field-value might
    differ from that sent in any previous response for the same
    variant

因此,如果原始缓存的响应已经包含Vary标头,那么这304个响应就不会是完全正确的。