I just set up Nginx, and I'm trying to use it to host a Laravel app, but I ran into 2 problems.
- For GET method, I always get an extra parameter in my inputs.
- Using PostMan (Chrome) to do my testings, I set the destination URL and my desired parameters and send the request. The output that I get, it always includes the
REQUEST_URI
which it shouldn't. Example output:
- Using PostMan (Chrome) to do my testings, I set the destination URL and my desired parameters and send the request. The output that I get, it always includes the
.
Array (
[/api/user] => // This shouldn't be here
[test] => test
)
- My parameters (the above) will NOT show for DELETE or PUT, at all, and for POST I'll only get the
REQUEST_URI
Nginx vhost (Followed Setting up Laravel w/ Nginx)
server {
server_name local.test.com;
root /var/www/test/public;
location / {
index index.php index.html index.htm;
}
# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
# The PHP Inclusion Block
# include /etc/nginx/includes/php;
location ~ \..*/.*\.php$ {
# I'm pretty sure this stops people trying to traverse your site to get to other PHP files
return 403;
}
#location ~ \.php$ {
location ~ \.php(.*)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
# Deny Any Access to .htaccess Files That May Be Present (not usually in issue in Laravel)
# include /etc/nginx/includes/deny_htaccess;
location ~ /\.ht
{
deny all;
}
error_log /var/www/logs/test-error.log;
}
fastcgi_params :
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
#fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
nginx.conf Has only 1 thing changed, and that is keepalive_timeout
from 65 to 15
So I absolutely have no clue, where all this thing goes wrong. But I do have to mention, that on another 2 environments that I have (One with Lighttpd and the other with Apache2) the app works perfectly.
From what I've noticed, its all reduced to the following code:
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
Which will make the GET work... and add the additional parameter
dd(Input::all());
it's what I'm outputting... and no, it's notInput::all()
that set the undesired parameter – Syconium