admin管理员组文章数量:1200964
I'm encountering an issue with my Nginx configuration.
Whenever I access a URL with GET parameters, such as or /?page=1, the server returns an HTTP 403 Forbidden error. However, the page works fine without parameters, e.g., /.
Nginx php 8.3 laravel 11
This is nginx code
server {
listen 80;
server_name dummy.example;
# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name dummy.example;
merge_slashes off;
# SSL Configuration
ssl_certificate /path/to/certificate/example.cer;
ssl_certificate_key /path/to/certificate/example.key;
ssl_trusted_certificate /path/to/certificate/example_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;
}
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;
}
Share
Improve this question
edited Jan 22 at 18:44
hakre
198k55 gold badges446 silver badges854 bronze badges
Recognized by PHP Collective
asked Jan 22 at 14:29
Abdulrahman OthmanAbdulrahman Othman
74 bronze badges
1 Answer
Reset to default -1I 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:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Just in case, I do have this one for location ~ \.php$
:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
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
本文标签: phpNginx returns 403 for URLs with GET parametersStack Overflow
版权声明:本文标题:php - Nginx returns 403 for URLs with GET parameters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738552804a2097697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论