framework icon indicating copy to clipboard operation
framework copied to clipboard

nginx config incorrect

Open sandrodz opened this issue 10 years ago • 7 comments

Hi.

I was getting 403 forbidden with nginx config described in docs. It is incomplete and was missing:

index index.php; directive.

centos7, using docker container for nginx and php7-fpm

sandrodz avatar May 09 '16 20:05 sandrodz

Hi, thanks for the report!

What makes you think that this is incorrect? It seems to work for many people...

franzliedke avatar May 10 '16 02:05 franzliedke

default nginx config doesn't have index index.php; and it tries to load index.html which doesn't exist and fails with 403 error.

sandrodz avatar May 10 '16 05:05 sandrodz

There is a directive

fastcgi_index index.php;

@sandrodz , do you have this module enabled in nginx? -> ngx_http_fastcgi_module

kulga avatar May 10 '16 17:05 kulga

@kulga

If you don't have index index.php; outside location directive, fastcgi_index index.php; inside location will never match.

I'm testing on official nginx docker image.

also this: http://stackoverflow.com/questions/30802025/what-is-fastcgi-index-in-nginx-used-for

sandrodz avatar May 10 '16 17:05 sandrodz

Oh, yep. That makes sense. After checking, I have index placed before existing flarum nginx config.

But technically, this still isn't complete since root, server_name and listen are not included either. Except for those, we can't possibly predict them.

Perhaps

location / { try_files $uri $uri/ /index.php?$query_string; } location /api { try_files $uri $uri/ /api.php?$query_string; } location /admin { try_files $uri $uri/ /admin.php?$query_string; }

Changed to

listen port;

root /flarum/location; index index.php;

server_name domain.tld;

location / { try_files $uri $uri/ /index.php?$query_string; } location /api { try_files $uri $uri/ /api.php?$query_string; } location /admin { try_files $uri $uri/ /admin.php?$query_string; }

kulga avatar May 10 '16 17:05 kulga

Well if you don't setup root, server_name and listen you will see the meaningful errors. But if you miss index index.php; you will just see bogus forbidden. threw me off for a sec.

but yeah, I think you should include the whole thing, and people will just edit relevant parts.

sandrodz avatar May 10 '16 17:05 sandrodz

Fixed by adding .nginx.conf to flarum/flarum (https://github.com/flarum/flarum/commit/b4a09a072f32f1c0fe6d0cfd210e1ea05bf423f6), used from within an existing Nginx configuration.

dsevillamartin avatar Jul 11 '19 12:07 dsevillamartin