在我的 nginx 配置中,我有以下内容:
location /admin/ {
alias /usr/share/php/wtlib_4/apps/admin/;
location ~* .*\.php$ {
try_files $uri $uri/ @php_admin;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air)$ {
expires 7d;
access_log off;
}
}
location ~ ^/admin/modules/([^/]+)(.*\.(html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {
alias /usr/share/php/wtlib_4/modules/$1/admin/$2;
}
location ~ ^/admin/modules/([^/]+)(.*)$ {
try_files $uri @php_admin_modules;
}
location @php_admin {
if ($fastcgi_script_name ~ /admin(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass $byr_pass;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4/apps/admin$valid_fastcgi_script_name;
fastcgi_param REDIRECT_STATUS 200;
include /etc/nginx/fastcgi_params;
}
location @php_admin_modules {
if ($fastcgi_script_name ~ /admin/modules/([^/]+)(.*)$) {
set $byr_module $1;
set $byr_rest $2;
}
fastcgi_pass $byr_pass;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4/modules/$byr_module/admin$byr_rest;
fastcgi_param REDIRECT_STATUS 200;
include /etc/nginx/fastcgi_params;
}
以下是以“404”结尾的请求 URL:
http://www.{domainname}.com/admin/modules/cms/styles/cms.css
以下是错误日志:
[error] 19551#0: *28 open() "/usr/share/php/wtlib_4/apps/admin/modules/cms/styles/cms.css" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: {domainname}.com, request: "GET /admin/modules/cms/styles/cms.css HTTP/1.1", host: "www.{domainname}.com"
下列 URL 可以正常工作:
http://www.{domainname}.com/admin/modules/store/?a=manage
http://www.{domainname}.com/admin/modules/cms/?a=cms.load
有人能看出问题出在哪里吗?谢谢。
PS. 我正在尝试将现有站点从 apache 迁移到 nginx。
答案1
看到您的请求已发送到 PHP,我会假设以下位置块与您的请求不匹配,尽管这是您的意图。
location ~ ^/admin/modules/([^/]+).*\.html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {
来自nginx 文档:
没有不匹配正则表达式的语法。相反,匹配目标正则表达式并分配一个空块,然后使用 location / 匹配其他任何内容。
您对该位置块中的部分有何意图([^/]+)
?我认为您只需删除该部分即可实现您的目的。
location ~ ^/admin/modules/.*\.html|js|json|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air))$ {