首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用Nginx设置Laravel

使用Nginx设置Laravel
EN

Stack Overflow用户
提问于 2012-01-14 04:12:54
回答 1查看 10.8K关注 0票数 21

我正在尝试设置使用NginxLaravel PHP框架。下面是我的目录结构:

代码语言:javascript
复制
/project
   /application
   /laravel
   /public
      index.php
   /legacy
      /index.php
      /stylesheets
         default.css

基本上,我有一个标准的Laravel下载和一个legacy文件夹,其中包含来自我的非MVC项目的所有文件。

我需要Nginx首先检查请求的页面/文件是否存在于遗留文件中,如果存在,则我想使用它。否则,我想退回到位于project/public/中的Laravel的index.php文件。

当涉及到Nginx配置时,我不是专家,所以您能提供的任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-22 01:30:45

代码语言:javascript
复制
server {
    server_name .laravel.dev;
    root /home/tamer/code/laravel/public;

    index index.php index.html;

    #browse folders if no index file
        autoindex on; 

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }


    # canonicalize codeigniter url end points
    # if your default controller is something other than "welcome" you should change the following
    if ($request_uri ~* ^(/lobby(/index)?|/index(.php)?)/?$)
    {
        rewrite ^(.*)$ / permanent;
    }

    # removes trailing "index" from all controllers
    if ($request_uri ~* index/?$)
    {
        rewrite ^/(.*)/index/?$ /$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # catch all
    error_page 404 /index.php;

        location ~ \.php$ {
        try_files $uri =404;
                fastcgi_pass  unix:/tmp/php.socket;
                fastcgi_index index.php;
                #include fastcgi_params;
                include /home/tamer/code/nginx/fastcgi_params;
        }
        access_log /home/tamer/code/laravel/storage/logs.access.log;
        error_log  /home/tamer/code/laravel/storage/logs.error.log;
}
票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8856664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档