All routes except '/' For LaravelNginx are 404

Source: Internet
Author: User
Yes. After I complete a Laravel project, I plan to transfer it to Nginx. The previous figure is convenient. Therefore, in the development environment, php-Slocalhost: 1234 is used to start the HTTP server, it is not developed in Nginx, and the server is Ubuntu14.10. Repeat the entire project... Yes. After I finish a Laravel project, I plan to transfer it to Nginx. The previous figure is convenient, so in the development environment php -S localhost:1234The HTTP server is not developed in Nginx. The server is Ubuntu 14.10.

Copy the entire project/usr/share/nginx/html, Modifyapp/storagePermission:777And then access/Yes, but/All other routes returned404For example/homeReturn404 NOT FOUNDBut there is no such problem during development. The database is okay, because the development is on the same machine.

The following is my Nginx configuration file:

configserver {    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 configuration file and add it:

configtry_files $uri $uri/ @rewrite;location @rewrite {    rewrite ^/(.*)$ /index.php?_url=/$1;}

Or404.

Later, I created a Laravel project under the Nginx root directory and modifiedapp/storageAccess to the root route after permission is normal, and access to other custom routes is the same404For example:

app/route.php

phpRoute::get('home', function(){    return View::make('hello');});

The level of food is really helpless. Thank you very much.

Reply content:

Yes. After I complete a Laravel project, I plan to transfer it to Nginx. The previous figure is convenient, so in the development environmentphp -S localhost:1234The HTTP server is not developed in Nginx. The server is Ubuntu 14.10.

Copy the entire project/usr/share/nginx/html, Modifyapp/storagePermission:777And then access/Yes, but/All other routes returned404For example/homeReturn404 NOT FOUNDBut there is no such problem during development. The database is okay, because the development is on the same machine.

The following is my Nginx configuration file:

configserver {    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 configuration file and add it:

configtry_files $uri $uri/ @rewrite;location @rewrite {    rewrite ^/(.*)$ /index.php?_url=/$1;}

Or404.

Later, I created a Laravel project under the Nginx root directory and modifiedapp/storageAccess to the root route after permission is normal, and access to other custom routes is the same404For example:

app/route.php

phpRoute::get('home', function(){    return View::make('hello');});

The level of food is really helpless. Thank you very much.

php -SOne fatal problem is that the 'Home' in the route must be written as '/Home' to work.

See http://lvwenhan.com/php/406.html

However, this problem seems to be a problem of targeting the portal file, that is, you did not send all non-static requests to the portal file.index.php. Don't forget to point the root directorylaravel/public.

Laravel does not know what it is, but it does not seem like WordPress directly parses the URI, but uses PATH_INFO to decide what to display.

Can you try to write the request rewrite to the PHP entry file? 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;}

For details, see the official Laravel documentation:
Http://laravel.com/docs/5.0/installation#pretty-urls

Location/{try_files $ uri // index. php;} Add a root file and try location/{root/var/www/try_files $ uri // index. php ;}

I used iis8 Win8 to encounter this 404 problem. After installing the Url Rewrite component for iis to import the htacss file, it will be fine.

Try_files $ uri = 404;
Comment out this line?
Http://www.yimiju.com/articles/593.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.