# Nginx & Moodle

## paul_chany

Hi,

I'm trying to setup Moodle with Nginx.

All packages: nginx, moodle have installed with emerge.

I have installed nginx/1.9.7.

I first installed moodle, after that installed moodle with webapp-config.

Now when try to open my Moodle at http://localhost/moodle I get error message: 

403 Forbidden

I'm following https://docs.moodle.org/29/en/Nginx .

/etc/nginx/nginx.conf

```
server {

                listen 80;

                server_name cspl.hu www.cspl.hu;

                access_log /var/log/nginx/localhost.access_log main;

                error_log /var/log/nginx/localhost.error_log info;

                root /var/www/localhost/htdocs;

                location ~ [^/]\.php(/|$) {

                    # Test for non-existent scripts or throw a 404 error

                    # Without this line, nginx will blindly send any request ending in .php to php-fpm

                    try_files $uri =404;

                    fastcgi_split_path_info  ^(.+\.php)(/.+)$;

                    fastcgi_index       index.php;

                    fastcgi_pass        unix:/run/php-fpm.socket;

                    include             fastcgi_params;

                    include             /etc/nginx/fastcgi.conf;

                    fastcgi_param       PATH_INFO       $fastcgi_path_info;

                    fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;

                }

                location /dataroot/ {

                    internal;

                    alias /var/www/localhost/moodle/; # ensure the path ends with /

                }

        }

```

What should I do to solve this problem?

----------

## gordonb3

You're missing a global try_files directive that tells nginx to load some default file if the uri is a directory.

Example:

```
try_files $uri $uri/index.html
```

----------

## paul_chany

Finally I set Nginx, Php-fpm and Moodle.

It works now.

Only the Bubba 2 headless server is to slow to handle http and php requests when I want to set my Moodle site up.

----------

