Report this

What is the reason for this report?

Can i can return 404 if file not exists?

Posted on December 2, 2019

Hello can i return 404 or 403 if anyone try to open /?a=b AND 1=1

My vhost is:

server {
listen 80;
listen [::]:80;
server_name mysite.com www.mysite.com;
root /var/www/mysite.com/public_html;
index index.php;
rewrite ^ https://$server_name$request_uri? permanent;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
root /var/www/mysite.com/public_html;
index index.php index.html index.htm index.nginx-debian.html;
server_name mysite.com www.mysite.com;
error_page 403 https://mysite.com/dead.html;

location = /dead.html {
allow all;
}

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 240;					 
fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\. {
deny all;
}

location ~ /\.ht {
access_log        off; 
log_not_found     off; 
deny              all; 
}
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Yes, I believe that with your current config it should work as expected as you have this part here:

location / {
    try_files $uri $uri/ =404;
}

I could suggest also taking a look at this article here on how to set up a custom 404 page with Nginx:

https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.