0

I'm not a sysadmin, I'm just a vision programmer who's trying to set up his friend's API in a localhost. I'm using nginx, and the config file my friend gave me was this:

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;
        }

}

I changed it to this and ran it:

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 runs file. The access and error log are being filled. But with these:

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"

And the error log:

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"

I don't understand. What could be wrong? It serves nothing. Either 403 or 404.

  • @RichardSmith I want it to run on localhost:90. What should I enter? – Major Despard Apr 20 at 8:03
  • 1
    The error log does not agree with the configuration file. The error log implies that the root is set to /var/www/api.chubak.com/html/. Use nginx -T (uppercase T) to test the configuration and see the entire configuration that Nginx is actually using. – Richard Smith Apr 20 at 8:09
  • @RichardSmith It says to root is /public... – Major Despard Apr 20 at 8:47
  • @RichardSmith It worked! I just needed to restart nginx. Thanks. – Major Despard Apr 20 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.