nginx 位置指令添加到 url 路径
nginx location directive is prepended to url path
我正在位置指令“/文件夹”中设置别名。别名指向“/my/alias/path”。
当我导航到该位置内的 URL 时,例如"mydomain.com/folder/destination",指令名称被添加到请求的前面,解析为
“/my/alias/path/folder/destination”(不需要)而不是
“/my/alias/path/目的地”(期望)。
我可能遗漏了什么或者不太了解位置和别名的工作原理。
我试过向位置指令和别名添加正斜杠,但这也不起作用。
这是我的位置指令:
location ^~ /folder {
alias /my/alias/path;
index index.php index.html index.htm;
location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
deny all;
}
location ~ ^/(bin|SQL)/ {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /.well-known/acme-challenge {
allow all;
}
}
这是我在 error.log
中看到的内容
/my/alias/path/folder/destination/index.php (No such file or directory)
错误与.php
文件有关,可能是由php-fpm产生的,因为SCRIPT_FILENAME
的值设置不正确。
在 snippets/fastcgi-php.conf
中,您可能将 SCRIPT_FILENAME
设置为 $document_root$fastcgi_script_name
,这与 alias
指令不兼容。请改用 $request_filename
。
例如:
location ^~ /folder {
alias /my/alias/path;
...
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
通过将 fastcgi_param
语句放在 include
语句之后,新值将自动覆盖不正确的值。
我正在位置指令“/文件夹”中设置别名。别名指向“/my/alias/path”。
当我导航到该位置内的 URL 时,例如"mydomain.com/folder/destination",指令名称被添加到请求的前面,解析为 “/my/alias/path/folder/destination”(不需要)而不是 “/my/alias/path/目的地”(期望)。
我可能遗漏了什么或者不太了解位置和别名的工作原理。
我试过向位置指令和别名添加正斜杠,但这也不起作用。
这是我的位置指令:
location ^~ /folder {
alias /my/alias/path;
index index.php index.html index.htm;
location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
deny all;
}
location ~ ^/(bin|SQL)/ {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /.well-known/acme-challenge {
allow all;
}
}
这是我在 error.log
中看到的内容/my/alias/path/folder/destination/index.php (No such file or directory)
错误与.php
文件有关,可能是由php-fpm产生的,因为SCRIPT_FILENAME
的值设置不正确。
在 snippets/fastcgi-php.conf
中,您可能将 SCRIPT_FILENAME
设置为 $document_root$fastcgi_script_name
,这与 alias
指令不兼容。请改用 $request_filename
。
例如:
location ^~ /folder {
alias /my/alias/path;
...
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
通过将 fastcgi_param
语句放在 include
语句之后,新值将自动覆盖不正确的值。