小编tom*_*ave的帖子

nginx:直接从位置发送到另一个命名位置

在我的 nginx 1.12.2conf 文件中,我有:

upstream app {
  server unix:/tmp/app.sock  fail_timeout=0;
}

server {
  listen 443 deferred;

  root /some/dir;

  try_files $uri @app;

  # If the request is for the naked domain, just serve the index bundle
  # without going through Rails
  #
  location = / {
    try_files /index.html =404;
  }

  # If the request if for the /api prefix, go directly to Rails.
  # This location block is not strictly required, but it could be a handy
  # customization hook …
Run Code Online (Sandbox Code Playgroud)

nginx

14
推荐指数
3
解决办法
2万
查看次数

nginx mime 类型和 gzip

Nginx 允许您将文件扩展名映射到 MIME 类型。正如文档所说,它甚至带有一个预先构建的 mime 类型列表(粘贴在问题的末尾)。

我一直相信这个列表,而且一切都很好,但现在我注意到缺少某些类型。

怎么样application/javascriptapplication/json

它使用旧的 deprecated application/x-javascript,我想这是为了确保 IE 支持......但它真的可以吗?


另外,应该压缩哪些类型?

我一直在以下代码段中使用该列表,尽管我承认它只是示例 nginx conf 文件的一部分,几年前我刚开始使用 nginx 时曾将其用作示例。

我还应该包括application/json吗?

http {
    include mime.types;
    default_type application/octet-stream;

    gzip_types text/plain text/xml text/css
               text/comma-separated-values
               text/javascript application/x-javascript
               application/atom+xml;

    # text/html is included in the gzip list by default                   

    # ...
}
Run Code Online (Sandbox Code Playgroud)

默认的 mime 类型为/etc/nginx/mime.types.

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/x-javascript              js;
    application/atom+xml …
Run Code Online (Sandbox Code Playgroud)

nginx mime

10
推荐指数
2
解决办法
3万
查看次数

nginx gzip_static:为什么需要非压缩文件?

我正在使用在Ubuntu 12.04.4上运行的nginx 1.4.4。 nginx 反向代理一组Rails应用程序服务器。

直接提供静态文件(主要是资产),而不会影响应用程序服务器。
我已将其设置为gzip响应并在可用时使用预压缩文件。

http {
  gzip on;
  gzip_http_version 1.0;
  gzip_proxied any;
  # other ngx_http_gzip_module directives...

  server {
    # proxy configuration

    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
      # root is inherited
      try_files $uri =404;
      error_page 404 /404.html;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这有效。
我已经使用真实的预压缩资产和具有相同名称但内容不同的虚拟非压缩资产对其进行了测试:

/assets/application-a45d6...e2593.css         # dummy content
/assets/application-a45d6...e2593.css.gz      # real CSS
Run Code Online (Sandbox Code Playgroud)

我可以看到这种切换,gzip_static onoff会导致 nginx 正确提供文件的预期版本。 …

nginx gzip

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

nginx ×3

gzip ×1

mime ×1