Laravel 4的nginx配置

 瓷娃娃2502929883 发布于 2023-02-03 11:48

我正在尝试使用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"错误.

2 个回答
  • 这是我使用的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;
        }
    
    }
    

    2023-02-03 11:49 回答
  • 你可以尝试这个位置/ {...}

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

    $ query_string对我有用.

    2023-02-03 11:49 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有