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:
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
