Laravel 4 的 nginx 配置

标签 nginx laravel laravel-4

我正在尝试使用 nginx 设置我的 Laravel 4 项目。这是我用于 laravel 的 nginx 服务器块:

server {
        listen 80;

        root /home/prism/www/laravel/public;
        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.php$is_args$args;

        }
               location ~ \.php$ {

                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

但我的问题是,除了默认安装的默认路由外,所有其他路由都显示“404 not found”错误。

最佳答案

这是我在 Laravel 4 和 Laravel 4.1 中使用的 NGINX 配置,该配置有效。

server {

    listen  80;
    server_name sub.domain.com;
    set $root_path '/var/www/html/application_name/public';
    root $root_path;

    index index.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

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

    location ~ \.php {

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }

}

关于Laravel 4 的 nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21091405/

相关文章:

php - 向 Laravel 的 Mailer 添加新的传输驱动程序

javascript - 如何在 laravel blade 中使用 vue.js 组件?

node.js - Node Express Unix 域套接字权限

nginx - JasperServer 代理 CSRF 错误

python - 使用 Nginx 和 gunicorn : permission denied when connecting to webpage. socks 的服务 flask 应用程序

json - 如何使用 eloquent 根据数据库关系返回 json 响应

php - 使用布局模板的 flash 消息重定向回来

php - Laravel:跟踪页面浏览量

php - 使用 Laravel 4 进行文件上传 mime 类型验证

python - Docker Nginx 不监听浏览器