尽管服务器正在运行并且正在写入日志文件,但 nginx 返回 404。在根目录中,它返回 403。详细信息请参见

尽管服务器正在运行并且正在写入日志文件,但 nginx 返回 404。在根目录中,它返回 403。详细信息请参见

我不是系统管理员,我只是一名视觉程序员,正在尝试在本地主机中设置他朋友的 API。我使用的是 nginx,我朋友给我的配置文件如下:

server {
        listen **.48.37.125:443 ssl http2;
        server_name api.**.com;
        access_log /srv/logs/api.access.log;
        error_log /srv/logs/api.error.log;
        root /srv/api/public;
        index index.php index.html;
        client_max_body_size 128M;
        location / {
            try_files $uri $uri/ /index.php?_url=$uri&$args;
        }
        location ~ \.php$ {
            include /etc/nginx/fastcgi.conf;
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_read_timeout 600;
            fastcgi_intercept_errors on;
            gzip off;
            fastcgi_index   index.php;
        }

}

我将其改为这样并运行它:

server {
        listen 90;
        server_name _;
        access_log /home/chubak/Share/logs/api.access.log;
        error_log /home/chubak/Share/logs/api.error.log;
        root /var/www/api.chubak.com/html/public;
        index index.php index.html;
        client_max_body_size 128M;
        location / {
            try_files $uri $uri/ /index.php?_url=$uri&$args;
        }
        location ~ \.php$ {
            include /etc/nginx/fastcgi.conf;
            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_read_timeout 600;
            fastcgi_intercept_errors on;
            gzip off;
            fastcgi_index   index.php;
        }

}

nginx -t运行文件。访问和错误日​​志正在被填满。但是有这些:

10.0.2.15 - - [20/Apr/2019:02:22:26 -0400] "GET /public/ HTTP/1.1" 404 104 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:23:23 -0400] "GET /public/api/v1/users HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:23:31 -0400] "GET /public/api/v1/user HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:23:52 -0400] "GET /api/v1/users HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:24:48 -0400] "GET /api/auth/authorise HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:24:58 -0400] "GET / HTTP/1.1" 403 140 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:25:08 -0400] "GET /public/ HTTP/1.1" 404 104 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
127.0.0.1 - - [20/Apr/2019:02:32:52 -0400] "POST /api/auth/authorise HTTP/1.1" 404 169 "-" "PostmanRuntime/7.6.0"
10.0.2.15 - - [20/Apr/2019:02:36:24 -0400] "GET /public/ HTTP/1.1" 404 104 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:47:09 -0400] "GET /public/ HTTP/1.1" 404 104 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:47:37 -0400] "GET /api/v1/members HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:51:46 -0400] "GET /api/v1/members HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:51:54 -0400] "GET / HTTP/1.1" 403 140 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
10.0.2.15 - - [20/Apr/2019:02:53:06 -0400] "GET /api/v1/users HTTP/1.1" 404 169 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

错误日志:

2019/04/20 02:24:58 [error] 10030#10030: *1 directory index of "/var/www/api.chubak.com/html/" is forbidden, client: 10.0.2.15, server: _, request: "GET / HTTP/1.1", host: "10.0.2.15:90"
2019/04/20 02:51:54 [error] 10030#10030: *9 directory index of "/var/www/api.chubak.com/html/" is forbidden, client: 10.0.2.15, server: _, request: "GET / HTTP/1.1", host: "10.0.2.15:90"

我不明白。可能出了什么问题?它什么也没提供。要么是 403,要么是 404。

相关内容