# Nginx Slim Error 404

**URL:** <https://discourse.slimframework.com/t/nginx-slim-error-404/4632>\
**Category:** Questions\
**Created:** [January 30, 2021, 11:20am UTC](https://discourse.slimframework.com/t/nginx-slim-error-404/4632 "2021-01-30T11:20:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratchaya](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pratchaya](https://discourse.slimframework.com/u/pratchaya)\
**Post date:** [January 30, 2021, 11:20am UTC](https://discourse.slimframework.com/t/nginx-slim-error-404/4632/1 "2021-01-30T11:20:11Z")

</div>

Hi , People

I have many ways , many method to set nginx for work fine with slim.  
But right now , I still got error 404.  
Please help or suggest me ? sir

Many Thanks.  
Pratchaya

```auto
######## This is my conf. 
server {
    # Port 80 will require Nginx to be started with root permissions
    # Depending on how you install Nginx to use port 80 you will need
    # to start the server with `sudo` ports about 1000 do not require
    # root privileges
    # listen 80;

    listen 80;
    server_name api.xxx.work;

   
    root /var/www/site/api/public_html/;
    index index.php index.html index.htm;

    charset utf-8;
    client_max_body_size 100M;
    fastcgi_read_timeout 1800;

    # Represents the root of the domain
    # http://localhost:8000/[index.php]
    location / {
        # Matches URLS `$_GET['_url']`
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    # When the HTTP request does not match the above
    # and the file ends in .php
    location ~ [^/]\.php(/|$) {
        # try_files $uri =404;

        # Ubuntu and PHP7.0-fpm in socket mode
        # This path is dependent on the version of PHP install
        #fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
	fastcgi_pass unix:/run/php-fpm/www.sock;

        # Alternatively you use PHP-FPM in TCP mode (Required on Windows)
        # You will need to configure FPM to listen on a standard port
        # https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/
        # fastcgi_pass 127.0.0.1:9000;

        fastcgi_index /index.php;

        include fastcgi_params;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        fastcgi_param PATH_INFO $fastcgi_path_info;
        # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        # and set php.ini cgi.fix_pathinfo=0

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max; log_not_found off;
        access_log off;
    }
}

```

 ![Screen Shot 2564-01-30 at 18.16.09](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/a/ae1ea3b4ab88d34d0fdea0fd9536c0cc1ebb9587.png)

PS. Only index.php ( normal code work fine )  
 ![Screen Shot 2564-01-30 at 18.19.04](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/d/d8422bd80901ef459dfb94be6acde244af82e64e.png)

 ![Screen Shot 2564-01-30 at 18.16.33](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/6/668056215d150d4c965e93bc0f37958c3268d135.png)

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [January 30, 2021, 12:58pm UTC](https://discourse.slimframework.com/t/nginx-slim-error-404/4632/2 "2021-01-30T12:58:13Z")

</div>

Have you tried to use the [Nginx example](https://www.slimframework.com/docs/v4/start/web-servers.html#nginx-configuration) from the official documentation?

I don’t see a `public/` directory with the `index.php` file.  
Make sure you have a `public/` directory and a `public/index.php` file.  
Then configure the Nginx `root /path/to/public;`

Also change `index index.php index.html index.htm;` to  
`index index.php;` as shown in the documentation.

Better take the example from the documentation and change it to your needs.

---

<div class="post-metadata">

**Author:** ![pratchaya](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pratchaya](https://discourse.slimframework.com/u/pratchaya)\
**Post date:** [January 30, 2021, 3:22pm UTC](https://discourse.slimframework.com/t/nginx-slim-error-404/4632/3 "2021-01-30T15:22:04Z")

</div>

Hi , Odan

Following your suggestion , I still got error.  
and I also attach screen capture about the folder, file structure for more information.

So , about nginx example with slim , I have already try before post in this board too.

Many Thanks  
Please help.  
Pratchaya

PS.

 ![Screen Shot 2564-01-30 at 22.21.47](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/7/71963acbe373c66b05f86d27dca5ec5109ce2f80.jpeg)

---

<div class="post-metadata">

**Author:** ![darkalchemy](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@darkalchemy](https://discourse.slimframework.com/u/darkalchemy)\
**Post date:** [January 30, 2021, 9:25pm UTC](https://discourse.slimframework.com/t/nginx-slim-error-404/4632/4 "2021-01-30T21:25:25Z")

</div>

Your web server root should only contain index.php and css/js/image files, everything thing else is usually 1 folder up, you have everything in the root.

Generally speaking, you don’t want everyone publicly available.
