I’m encountering an issue with my Nginx configuration.
Whenever I access a URL with GET parameters, such as https://example.com?id=32 or http://example.com/?page=1, the server returns an HTTP 403 Forbidden error. However, the page works fine without parameters, e.g., https://example.com/.
Nginx
php 8.3
laravel 11
This is nginx code
server {
listen 80;
server_name dummy.example.com;
# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name dummy.example.com;
merge_slashes off;
# SSL Configuration
ssl_certificate /path/to/certificate/example.com.cer;
ssl_certificate_key /path/to/certificate/example.com.key;
ssl_trusted_certificate /path/to/certificate/example.com_chain.cer;
# SSL Optimization
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:10m;
# Laravel Backend
root /var/www/html/example/backend/public;
index index.php index.html;
# Laravel route handling
location / {
try_files $uri /index.php?$query_string;
try_files $uri $uri/ /index.php$is_args$args;
}
# PHP FastCGI Configuration for Laravel
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny Access to Hidden and Sensitive Files
# location ~ /.(?!well-known).* {
# deny all;
# }
# Logging
error_log /var/log/nginx/dummy_error.log;
access_log /var/log/nginx/dummy_access.log;
}
2
Answers
Does it help if you put a slash in front of the query portion of the URL?
So: https://example.com/?id=32
This communicates to the server that you call the default file on it with the GET parameters.
I am not a guru with Nginx nor Aparche, but I think your issue is around
location /
.This is what I have and I think it will work for you:
Just in case, I do have this one for
location ~ .php$
:You can always resort to the official documentation and extrictly follow it to check if with the laravel recommendation, works as expected: https://laravel.com/docs/11.x/deployment#nginx