大网数据广告活动
服务器运维问答

NGINX + Symfony - what is the internal directive redirecting to?

· 52CE 我爱测

Over at the official NGINX docs, they have the following configuration for production-level Symfony: # PROD location ~ ^/app\.php(/|$) { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include …

问题原文

原帖链接 · Major Productions · CC BY-SA 3.0

Over at the official NGINX docs, they have the following configuration for production-level Symfony:

# PROD
location ~ ^/app\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
   # When you are using symlinks to link the document root to the
   # current version of your application, you should pass the real
   # application path instead of the path to the symlink to PHP
   # FPM.
   # Otherwise, PHP's OPcache may not properly detect changes to
   # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
   # for more information).
   fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
   fastcgi_param DOCUMENT_ROOT $realpath_root;
   # Prevents URIs that include the front controller. This will 404:
   # http://domain.tld/app.php/some-path
   # Remove the internal directive to allow URIs like this
   internal;
}

The full configuration file can be found here

What is internal actually redirecting to? The comments say that it removes the front controller from the URI, but I'm not entirely sure how.

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 3.0

It doesn't redirect anything. It specifies how external redirections, i.e. locations like http://example.com/app.php/some-path should be handled; while set, they should return 404, only allowing internal redirections. Conditions handled as internal redirections are listed in the documentation for internal directive:

Specifies that a given location can only be used for internal requests. For external requests, the client error 404 (Not Found) is returned. Internal requests are the following:

  • requests redirected by the error_page, index, random_index, and try_files directives;
  • requests redirected by the X-Accel-Redirect response header field from an upstream server;
  • subrequests formed by the include virtual command of the ngx_http_ssi_module module and by the ngx_http_addition_module module directives;
  • requests changed by the rewrite directive.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。