【问题标题】:Does nginx line ordering within a location matters?一个位置内的 nginx 行排序是否重要?
【发布时间】:2020-09-29 11:25:39
【问题描述】:

具体我有以下位置:

location / {
    root ...;
    try_files $uri $uri/ /index.html =404;
    ....
    add_header ....
    server_tokens off;
    # Does the order of the next 2 lines matter?
    include uwsgi_params;
    uwsgi_pass django;
  }

我想知道其中行的顺序是否重要。特别是关于最后两行。

【问题讨论】:

  • 最后两行的顺序应该不重要。你遇到问题了吗?如果有,uwsgi_params 文件中有什么内容?
  • 我没有遇到问题。只是学习。找不到任何提及此的地方

标签: nginx uwsgi


【解决方案1】:

我找不到任何文档来回答“位置块中的指令顺序是否重要?”这个问题。但是,通过研究Nginx uwsgi module document中的例子,如下:

location / {
    include    uwsgi_params;
    uwsgi_pass localhost:9000;
}

location / {
    uwsgi_pass        backend;
    uwsgi_cache       cache_zone;
    uwsgi_cache_key   $uri;
    uwsgi_cache_purge $purge_method;
}

location /fetch/ {
    internal;

    uwsgi_pass         backend:9000;
    ...

    uwsgi_store        on;
    uwsgi_store_access user:rw group:rw all:r;
    uwsgi_temp_path    /data/temp;

    alias              /data/www/;
}

我猜uwsgi_pass 指令和其他uwsgi_param 指令在uwsgi_params 文件中的顺序并不重要。如您所见,uwsgi_pass 指令可以位于块的开头、中间或结尾。

此外,在解释how to use NGINX as an application gateway with uWSGI and Django 的文章中,uwsgi_pass 指令也可以位于uwsgi_param 指令之间,如下所示:

location /main {
    include /etc/nginx/uwsgi_params;
    uwsgi_pass django;
    uwsgi_param Host $host;
    uwsgi_param X-Real-IP $remote_addr;
    uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
    uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
}

根据我在使用 FastCGI 设置 PHP 网站时的经验,指令的顺序无关紧要。但是,如果你在一个块中多次声明同一个指令,最后声明的指令将生效

【讨论】:

    猜你喜欢
    • 2011-08-25
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2022-12-25
    • 1970-01-01
    • 2011-09-05
    • 2010-10-18
    • 2013-12-16
    相关资源
    最近更新 更多