1

My nginx returns 404? I'm not sure why

Here is my /sites-available/default file, nginx.conf is default I haven't changed anything.

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/example.com/htdocs/public;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name example.com www.example.com;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

    location ~ /\.ht {
      deny all;
    }

}
  • Please be more specific and provide more details. What would you like to serve with nginx? A specific app or just an example php file? Did you create a symlink for you vhost config file from /sites-available/ to /sites-enabled/? Did you restart nginx after config file changes? What does your nginx log files say? Is there an index.php file in your document root /var/www/example.com/htdocs/public? Is server name 'example.com' just obfuscated or do you maybe need to enter your own domain here? Is php7.0-fpm installed? Why to you have a second 'try_files' in the location ~ \.php$ ? – Bob Feb 11 '18 at 6:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.