NGINX 解析器指令放置和继承

NGINX 解析器指令放置和继承

我的 nginx.conf 文件仅包含 1 个服务器块。

我最近阅读了一些指南并开始在我的 nginx 服务器块上下文中使用以下指令。

具体来说 resolverresolver_timeout

# Using ipv4 to listen on port 80

listen            80 default_server;

# Using ipv6 to listen on port 80

listen            [::]:80 default_server;

# Sets names of a virtual server

server_name       mysite.com www.mysite.com;

# Sets the root directory for requests

root              /usr/share/nginx/html;

# Configures name servers used to resolve names of upstream servers into addresses
# The IP addresses for Google Public DNS are 8.8.8.8 and 8.8.4.4
# By default, nginx caches answers using the TTL value of a response.
# An optional valid parameter allows overriding it.

resolver          8.8.8.8 8.8.4.4 valid=300s;

# Sets a timeout for name resolution

resolver_timeout  30s;

我有一些问题可能看起来很幼稚,但这是因为我想完全理解它。

问题 1- 我的域的 DNS 托管提供商包含 mysite.com 的 A 记录,该记录指向我的静态 IP 地址,TTL 为 1H。这是否意味着我必须将解析器与此值同步?

问题2- 鉴于 Google 的全球庞大基础设施,其公共 DNS 似乎是最佳选择。是否可以仅在http比服务器高一级的上下文中使用解析器指令,或者将其放在服务器块中是最佳做法?

问题 3- 如果我使用php-fpm,解析器指令是否最好放在fastcgi_pass位置块中,或者它们是否可以保留在服务器块中,并且由于级联一切都将正常工作?

# PHP scripts location block
location ~ \.php$ {

  # Security Setting #9 -> Use try_files to check if php script being passed 
  # is a file that actually exists.
  try_files       $uri =404;

  # Sets the address of a FastCGI server.
  # 
  # The address can be specified as a unix socket file, a domain name or IP address,
  # and a port.
  # 
  # In linux, we pass the PHP scripts to the PHP FastCGI Process Manager listening on 
  # a unix socket file.
  fastcgi_pass    unix:/run/php/php7.3-fpm.sock;

  # Sets a file name that will be appended after a URI that ends with a slash, in the value
  # of the $fastcgi_script_name variable.
  fastcgi_index   index.php;

  # You can use NGINX to "sanitize" the input to the application by setting the
  # HTTP_PROXY fastcgi_param to an empty string. This removes the parameter completely
  # from the FastCGI Process Manager request.
  fastcgi_param   HTTP_PROXY "";

  # Requires the server to use the root  directive
  # Requires the server to use the index directive
  fastcgi_param   SCRIPT_FILENAME  $request_filename;

  # Includes another file, or files matching the specified mask, into configuration.
  # Included files should consist of syntactically correct directives and blocks.

  # Includes adittional paramaters from fastcgi_params file.
  include         fastcgi_params;

} # END location block

相关内容