相关疑难解决方法(0)

Nginx 最佳实践

您在使用 NGinx 时使用了哪些最佳实践?

nginx httpd

46
推荐指数
9
解决办法
4万
查看次数

我如何干掉这个 Nginx 配置?

我在Nginx 0.8.54 上尝试尽可能 DRYly 实现以下目标:

  • 直接代理到localhost:8060cookie no_cacheistrue或 if request method is not GET
  • 否则从$document_root/static/$uri.
  • 如果不存在这样的文件,请尝试$document_root/cache/$uri$document_root/cache/$uri.html
  • 如果请求路径是/,请不要尝试静态文件,而只尝试$document_root/cache/index.html.
  • 最后回退到localhost:8060既没有找到静态文件也没有找到缓存文件的情况。

当前配置文件:

server {
    root /srv/web/example.com;
    server_name example.com;

    location @backend { proxy_pass http://localhost:8060; }

    location / {
        if ($cookie_no_cache = true) { proxy_pass http://localhost:8060; }
        if ($request_method != GET) { proxy_pass http://localhost:8060; }
        try_files /static/$uri /cache/$uri /cache/$uri.html @backend;
    }

    location = / {
        if …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy

5
推荐指数
1
解决办法
2077
查看次数

标签 统计

nginx ×2

httpd ×1

reverse-proxy ×1