403 is forbidden in wordpress index with nginx, other pages work fine

I am setting up my blog on a new instance of EC2 because one of the sites on the server that currently hosts it is DDoSed. I have problems with nginx, because I can either see all the pages in order, but 403 in the index, or see the index, but 404 in the pages (depending on the configuration used)

Here is my nginx configuration:

server { listen 80; server_name www.test.com; server_name test.com; root /www/blog; include conf.d/wordpress/simple.conf; } 

And simple.conf:

 location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't break when using query string try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini include fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } 

if I change try_files $ uri $ uri // index.php? $ args; for index.php , the first page will work fine and the rest will be 404. If I leave it like this, the first page will be 403.

Here's the error log:

 2013/08/07 19:19:41 [error] 25333#0: *1 directory index of "/www/blog/" is forbidden, client: 64.129.XX, server: test.com, request: "GET / HTTP/1.1", host: "www.test.com" 

This directory has a value of 755 for user nginx:

 drwxr-xr-x 6 nginx nginx 4096 Aug 7 18:42 blog 

Is there something obvious I'm doing wrong?

Thanks!

+6
source share
3 answers

Add index index.php; In the server block, if it does not work, you need to remove $uri/ , because you do not want to do autoindex on


EDIT : just noticed that you already figured out your problem, so I will add the arguments behind this, the reason you need autoindex on; because without it nginx will follow the rules of try_files ,
  • Check if there is a file named / , and of course it does not work.
  • Check if there is a directory called / (adding root it would = /www/blog/ ), this check will succeed, so it will try to list the contents of the folder.
  • Since you did not specify autoindex on; , therefore, by default, nginx should prohibit directory listing, so it will return a 403 forbidden error.
  • The rest of the site works fine because it fails in the $uri/ test or fails to achieve this because you probably don't have a folder named image.jpg or stylesheet.css , etc.
+17
source

It looks like I need inded index.php in the server definition {}, not in the location {}

+1
source

It looks like you are not allowing arguments to be sent to the CMS so that it does not display this uris, which would bring information from the database and redirect you to page 403.

0
source

Source: https://habr.com/ru/post/951249/


All Articles