繁体   English   中英

nginx api/index.php/explorer url 给出 404 错误

[英]nginx api/index.php/explorer url gives 404 error

我的问题是我无法打开如下所示的 url: http://myhost.mydomain.xx/.../api/index.php/explorer (这实际上是 dolibarr crm 的网络服务 url,但事实并非如此那很重要)我正在使用 nginx 和 php_fastcgi。 这是 nginx 中我的默认站点配置的相关部分:

server {
listen 80 default_server;
server_name myhost.mydomain.xx;
root /var/www/html;
index index.php index.html;
error_log     /var/log/nginx/myhost_error.log debug;
location ~ \.php$ {
#   location ~* \.php(/|$) {
#   location ~ \.php {
    try_files $uri =404;
#       try_files $uri /index.php/$uri /index.php/$uri&$args /index.php?q=$uri&$args;
#       try_files $uri /index.php/$uri;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout 600;
    include fastcgi_params;
    access_log /var/log/nginx/php-access.log;
    error_log /var/log/nginx/php-error.log debug;
}
#   return 301 https://$host$request_uri;
    if ($lan-ip = yes) {
        set $allowed_country yes;
    }
    if ($allowed_country = no) {
        return 404;
    }

}

如您所见,我尝试了几个 try_files 和几个位置指令,因为我用谷歌搜索了不同的关键字以试图找到答案。 但没有一个有效。 这对我来说并不奇怪,因为我真的不知道我在用不同的设置做什么。

我得到的最接近的是原始设置:

try_files $uri =404;

location ~ \.php$

但是这样 nginx “认为”我试图打开的 url 是一个目录。

(我把nginx的调试错误日志复制过来供参考,也许不是没有必要)

我的感觉是 location 指令的格式很糟糕,但我不得不承认正则表达式完全逃脱了我。

我的问题是位置指令的正确形式是什么,所以 nginx 不认为 url 是一个目录?

-------------- 来自这里的日志文件------------------------

2018/07/02 09:57:01 [debug] 12156#12156: *2 post event 000055D561CC4740
2018/07/02 09:57:01 [debug] 12156#12156: *2 delete posted event 000055D561CC4740
2018/07/02 09:57:01 [debug] 12156#12156: *2 http wait request handler
2018/07/02 09:57:01 [debug] 12156#12156: *2 malloc: 000055D561C37B10:1024
2018/07/02 09:57:01 [debug] 12156#12156: *2 recv: fd:19 713 of 1024
2018/07/02 09:57:01 [debug] 12156#12156: *2 reusable connection: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 posix_memalign: 000055D561C494B0:4096 @16
2018/07/02 09:57:01 [debug] 12156#12156: *2 http process request line
2018/07/02 09:57:01 [debug] 12156#12156: *2 http request line: "GET /szlatest/htdocs/api/index.php/explorer HTTP/1.1"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http uri: "/szlatest/htdocs/api/index.php/explorer"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http args: ""
2018/07/02 09:57:01 [debug] 12156#12156: *2 http exten: ""
2018/07/02 09:57:01 [debug] 12156#12156: *2 posix_memalign: 000055D561C93350:4096 @16
2018/07/02 09:57:01 [debug] 12156#12156: *2 http process request header line
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Host: myhost.mydomain.xx"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Accept-Language: en-US,en;q=0.5"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Accept-Encoding: gzip, deflate"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Referer: http://myhost.mydomain.xx/szlatest/htdocs/api/admin/index.php?save_lastsearch_values=1&backtopage=%2Fszlatest%2Fhtdocs%2Fadmin%2Fmodules.php%3Fsearch_nature%3D%26search_version%3D%26search_status%3D"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Cookie: DOLSESSID_941680c9ddfcaf66fd679287f56ff4cc=fkvdp2p8cb904h6q748r1ta391; DOLSESSTIMEOUT_7fb3b781cffd0a3d832ea68f0ebf83220634fa57=1440"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Connection: keep-alive"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header: "Upgrade-Insecure-Requests: 1"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http header done
2018/07/02 09:57:01 [debug] 12156#12156: *2 event timer del: 19: 1530518279502
2018/07/02 09:57:01 [debug] 12156#12156: *2 generic phase: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 rewrite phase: 1
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script var
2018/07/02 09:57:01 [debug] 12156#12156: *2 http geo started: xxx.xxx.xxx.xxx
2018/07/02 09:57:01 [debug] 12156#12156: *2 http geo: no
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script var: "no"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script value: "yes"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script equal
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script equal: no
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script if
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script if: false
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script var
2018/07/02 09:57:01 [debug] 12156#12156: *2 http map started
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script var: "HU"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http map: "HU" "yes"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script var: "yes"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script value: "no"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script equal
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script equal: no
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script if
2018/07/02 09:57:01 [debug] 12156#12156: *2 http script if: false
2018/07/02 09:57:01 [debug] 12156#12156: *2 test location: ~ "\.php$"
2018/07/02 09:57:01 [debug] 12156#12156: *2 using configuration ""
2018/07/02 09:57:01 [debug] 12156#12156: *2 http cl:-1 max:1048576
2018/07/02 09:57:01 [debug] 12156#12156: *2 rewrite phase: 3
2018/07/02 09:57:01 [debug] 12156#12156: *2 post rewrite phase: 4
2018/07/02 09:57:01 [debug] 12156#12156: *2 generic phase: 5
2018/07/02 09:57:01 [debug] 12156#12156: *2 generic phase: 6
2018/07/02 09:57:01 [debug] 12156#12156: *2 generic phase: 7
2018/07/02 09:57:01 [debug] 12156#12156: *2 access phase: 8
2018/07/02 09:57:01 [debug] 12156#12156: *2 access phase: 9
2018/07/02 09:57:01 [debug] 12156#12156: *2 access phase: 10
2018/07/02 09:57:01 [debug] 12156#12156: *2 post access phase: 11
2018/07/02 09:57:01 [debug] 12156#12156: *2 try files phase: 12
2018/07/02 09:57:01 [debug] 12156#12156: *2 content phase: 13
2018/07/02 09:57:01 [debug] 12156#12156: *2 content phase: 14
2018/07/02 09:57:01 [debug] 12156#12156: *2 content phase: 15
2018/07/02 09:57:01 [debug] 12156#12156: *2 content phase: 16
2018/07/02 09:57:01 [debug] 12156#12156: *2 content phase: 17
2018/07/02 09:57:01 [debug] 12156#12156: *2 http filename: "/var/www/html/szlatest/htdocs/api/index.php/explorer"
2018/07/02 09:57:01 [debug] 12156#12156: *2 add cleanup: 000055D561C4A440
2018/07/02 09:57:01 [error] 12156#12156: *2 open() "/var/www/html/szlatest/htdocs/api/index.php/explorer" failed (20: Not a directory), client: xxx.xxx.xxx.xxx, server: myhost.mydomain.xx, request: "GET /szlatest/htdocs/api/index.php/explorer HTTP/1.1", host: "myhost.mydomain.xx", referrer: "http://myhost.mydomain.xx/szlatest/htdocs/api/admin/index.php?save_lastsearch_values=1&backtopage=%2Fszlatest%2Fhtdocs%2Fadmin%2Fmodules.php%3Fsearch_nature%3D%26search_version%3D%26search_status%3D"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http finalize request: 404, "/szlatest/htdocs/api/index.php/explorer?" a:1, c:1
2018/07/02 09:57:01 [debug] 12156#12156: *2 http special response: 404, "/szlatest/htdocs/api/index.php/explorer?"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http set discard body
2018/07/02 09:57:01 [debug] 12156#12156: *2 xslt filter header
2018/07/02 09:57:01 [debug] 12156#12156: *2 HTTP/1.1 404 Not Found
Server: nginx/1.10.3 (Ubuntu)
Date: Mon, 02 Jul 2018 07:57:01 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Content-Encoding: gzip

2018/07/02 09:57:01 [debug] 12156#12156: *2 write new buf t:1 f:0 000055D561C93888, pos 000055D561C93888, size: 195 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 http write filter: l:0 f:0 s:195
2018/07/02 09:57:01 [debug] 12156#12156: *2 http output filter "/szlatest/htdocs/api/index.php/explorer?"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http copy filter: "/szlatest/htdocs/api/index.php/explorer?"
2018/07/02 09:57:01 [debug] 12156#12156: *2 image filter
2018/07/02 09:57:01 [debug] 12156#12156: *2 xslt filter body
2018/07/02 09:57:01 [debug] 12156#12156: *2 http postpone filter "/szlatest/htdocs/api/index.php/explorer?" 000055D561C4A4A0
2018/07/02 09:57:01 [debug] 12156#12156: *2 http gzip filter
2018/07/02 09:57:01 [debug] 12156#12156: *2 malloc: 000055D561C3C0C0:12288
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip alloc: n:1 s:5936 a:8192 p:000055D561C3C0C0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip alloc: n:512 s:2 a:1024 p:000055D561C3E0C0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip alloc: n:512 s:2 a:1024 p:000055D561C3E4C0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip alloc: n:512 s:2 a:1024 p:000055D561C3E8C0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip alloc: n:256 s:4 a:1024 p:000055D561C3ECC0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in: 000055D561C93A88
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in_buf:000055D561C93950 ni:000055D55FD10700 ai:116
2018/07/02 09:57:01 [debug] 12156#12156: *2 malloc: 000055D561C3F0D0:4096
2018/07/02 09:57:01 [debug] 12156#12156: *2 deflate in: ni:000055D55FD10700 no:000055D561C3F0D0 ai:116 ao:4096 fl:0 redo:0
2018/07/02 09:57:01 [debug] 12156#12156: *2 deflate out: ni:000055D55FD10774 no:000055D561C3F0D0 ai:0 ao:4096 rc:0
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in_buf:000055D561C93950 pos:000055D55FD10700
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in: 000055D561C93A98
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in_buf:000055D561C939A0 ni:000055D55FD10E40 ai:62
2018/07/02 09:57:01 [debug] 12156#12156: *2 deflate in: ni:000055D55FD10E40 no:000055D561C3F0D0 ai:62 ao:4096 fl:4 redo:0
2018/07/02 09:57:01 [debug] 12156#12156: *2 deflate out: ni:000055D55FD10E7E no:000055D561C3F14B ai:0 ao:3973 rc:1
2018/07/02 09:57:01 [debug] 12156#12156: *2 gzip in_buf:000055D561C939A0 pos:000055D55FD10E40
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C3C0C0
2018/07/02 09:57:01 [debug] 12156#12156: *2 http chunk: 10
2018/07/02 09:57:01 [debug] 12156#12156: *2 http chunk: 131
2018/07/02 09:57:01 [debug] 12156#12156: *2 write old buf t:1 f:0 000055D561C93888, pos 000055D561C93888, size: 195 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 write new buf t:1 f:0 000055D561C93BF8, pos 000055D561C93BF8, size: 4 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 write new buf t:0 f:0 0000000000000000, pos 000055D55FD13AC0, size: 10 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 write new buf t:1 f:0 000055D561C3F0D0, pos 000055D561C3F0D0, size: 131 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 write new buf t:0 f:0 0000000000000000, pos 000055D55FAE3819, size: 7 file: 0, size: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 http write filter: l:1 f:1 s:347
2018/07/02 09:57:01 [debug] 12156#12156: *2 http write filter limit 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 writev: 347 of 347
2018/07/02 09:57:01 [debug] 12156#12156: *2 http write filter 0000000000000000
2018/07/02 09:57:01 [debug] 12156#12156: *2 http copy filter: 0 "/szlatest/htdocs/api/index.php/explorer?"
2018/07/02 09:57:01 [debug] 12156#12156: *2 http finalize request: 0, "/szlatest/htdocs/api/index.php/explorer?" a:1, c:1
2018/07/02 09:57:01 [debug] 12156#12156: *2 set http keepalive handler
2018/07/02 09:57:01 [debug] 12156#12156: *2 http close request
2018/07/02 09:57:01 [debug] 12156#12156: *2 http log handler
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C3F0D0
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 0000000000000000
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C494B0, unused: 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C93350, unused: 1272
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C37B10
2018/07/02 09:57:01 [debug] 12156#12156: *2 hc free: 0000000000000000 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 hc busy: 0000000000000000 0
2018/07/02 09:57:01 [debug] 12156#12156: *2 tcp_nodelay
2018/07/02 09:57:01 [debug] 12156#12156: *2 reusable connection: 1
2018/07/02 09:57:01 [debug] 12156#12156: *2 event timer add: 19: 65000:1530518286165
2018/07/02 09:57:01 [debug] 12156#12156: *2 post event 000055D561CC4740
2018/07/02 09:57:01 [debug] 12156#12156: *2 delete posted event 000055D561CC4740
2018/07/02 09:57:01 [debug] 12156#12156: *2 http keepalive handler
2018/07/02 09:57:01 [debug] 12156#12156: *2 malloc: 000055D561C37B10:1024
2018/07/02 09:57:01 [debug] 12156#12156: *2 recv: fd:19 -1 of 1024
2018/07/02 09:57:01 [debug] 12156#12156: *2 recv() not ready (11: Resource temporarily unavailable)
2018/07/02 09:57:01 [debug] 12156#12156: *2 free: 000055D561C37B10

必须先从URI分离路径信息(使用fastcgi_split_path_info指令),然后才能评估脚本名称。 因此,不能在此处使用try_files ,而需要使用不流行的if块。

从官方示例:

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    ...
}

有关详细信息,请参见此文档

我留下这个以防它对任何人有帮助。 你必须配置如下。 我也在使用 dolibarr 并且遇到了同样的问题

location / {

    try_files $uri $uri/ /index.php?$query_string;
    

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        if (!-f $document_root$fastcgi_script_name) {
            return  404;
        }

        fastcgi_pass    127.0.0.1:9002;
        fastcgi_index   index.php;
        include         /etc/nginx/fastcgi_params;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM