So, I finished a Laravel project, I intend to transfer it to Nginx, before the diagram is convenient, so in the development environment are
php -S localhost:1234
To start the HTTP server, and did not develop under Nginx, the server is Ubuntu 14.10.
After the entire project is copied to, /usr/share/nginx/html
modify the app/storage
permissions for 777
, and then the browser access /
can be accessed, but in addition to /
routing the other routes all return 404
, such as /home
return 404 NOT FOUND
, and at the time of development there are no such problems. Database these are all fine, because the development is on the same machine.
Here is my Nginx configuration file:
config
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ /index.php; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =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; }}
I saw the same problem in StackOverflow, so I tried to modify my Nginx config file to add:
config
try_files $uri $uri/ @rewrite;location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1;}
Still, it was 404
not resolved.
Later, I created a new Laravel project under the Nginx root directory, the app/storage
access root route is normal after the permissions are modified, and the other custom routes are accessed 404
as well, such as:
app/route.php
php
Route::get('home', function(){ return View::make('hello');});
The level of real food, is really helpless, please master troubleshoot, thank you very much.
Reply content:
Yes, I finished a Laravel project, I intend to transfer it to Nginx, before the diagram is convenient, so in the development environment is php -S localhost:1234
to start the HTTP server, and did not develop under Nginx, the server is Ubuntu 14.10.
After the entire project is copied to, /usr/share/nginx/html
modify the app/storage
permissions for 777
, and then the browser access /
can be accessed, but in addition to /
routing the other routes all return 404
, such as /home
return 404 NOT FOUND
, and at the time of development there are no such problems. Database these are all fine, because the development is on the same machine.
Here is my Nginx configuration file:
config
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ /index.php; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =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; }}
I saw the same problem in StackOverflow, so I tried to modify my Nginx config file to add:
config
try_files $uri $uri/ @rewrite;location @rewrite { rewrite ^/(.*)$ /index.php?_url=/$1;}
Still, it was 404
not resolved.
Later, I created a new Laravel project under the Nginx root directory, the app/storage
access root route is normal after the permissions are modified, and the other custom routes are accessed 404
as well, such as:
app/route.php
php
Route::get('home', function(){ return View::make('hello');});
The level of real food, is really helpless, please master troubleshoot, thank you very much.
php -S
One of the deadly problems is that the ' home ' in routing must be written as '//' to work.
See http://lvwenhan.com/php/406.html
But your problem seems to be a problem with the directed entry file, which means that not all non-static requests are sent to the portal file index.php
. Finally, don't forget to point to the root directory laravel/public
.
Laravel is what I do not know, but it seems that it is not the kind of WordPress directly parse URI, but use Path_info to decide what content to show.
Do you try to rewrite the request to the PHP entry file? Look like this:
location / { rewrite ^/(/.*)?$ /index.php$1 last;}location = / { index index.php;}location ~ (.+\.php\d?)($|/) { fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; set $script $request_filename; if ($request_filename ~ ^(.+\.php\d?)(/.*)$){ set $script $1; set $pathinfo $2; } fastcgi_param PATH_INFO $pathinfo if_not_empty; fastcgi_param SCRIPT_FILENAME $script; include fastcgi_params;}
location / { try_files $uri $uri/ /index.php?$query_string;}
See Laravel official Documentation:
Http://laravel.com/docs/5.0/installation#pretty-urls
location / { try_files $uri $uri/ /index.php;}加一个 root 试试location / { root /var/www/ try_files $uri $uri/ /index.php;}
I used the Iis8 Win8 encountered this 404 problem, to IIS loaded with the URL rewrite component import htacss file is good
Try_files $uri = 404;
To comment out this line?
Http://www.yimiju.com/articles/593.html