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

时间:2018-07-02 09:03:33

标签: php url nginx

我的问题是我无法打开如下所示的网址: http://myhost.mydomain.xx/.../api/index.php/explorer (实际上,这是dolibarr crm的Web服务URL,但那并不重要) 我在php_fastcgi中使用nginx。 这是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;
    }

}

如您所见,我在Google搜索了不同的关键字以尝试找到答案时,尝试了一些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

1 个答案:

答案 0 :(得分:0)

在可以评估脚本名称之前,需要从URI(使用fastcgi_split_path_info指令)中分离路径信息。因此,try_files不能在这里使用,而必须使用不流行的if块。

在官方示例中:

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

有关详细信息,请参见this document