Laravel 5 - NGINX Server Config Issue with URL Query Strings

梦想的初衷 提交于 2019-12-03 04:03:23

This appears correct, aside from being commented out.

location / {
    #try_files $uri $uri/ /index.php?$query_string;
}

The bare bones one I use in testing is:

server {
    listen 80 default_server;

    root /var/www/project/public;
    index index.php
    server_name localhost;
    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
    }
}

$query_string and $args are functionally identical according to: NGINX Docs

This is the sites-enabled NGINX server configuration that ended up working for me...

server {
    listen 80;
    server_name registration.app;
    root /home/vagrant/Code/registration/public;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/registration.app-error.log error;
    error_page 404 /index.php;
    sendfile off;

    # Point index to the Laravel front controller.
    index index.php;

    location / {
        try_files $uri $uri/ index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        #deny all;
    }
}

For me it worked only by changing try_files $uri $uri/ /index.php?$query_string; to try_files $uri $uri/ /index.php?$args inside location / block on ubuntu (14.04) nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!