Настройка Laravel с помощью Nginx - PullRequest
20 голосов
/ 14 января 2012

Я пытаюсь настроить Laravel PHP Framework для работы с Nginx . Вот моя структура каталогов:

/project
   /application
   /laravel
   /public
      index.php
   /legacy
      /index.php
      /stylesheets
         default.css

По сути, у меня есть стандартная Laravel загрузка с брошенной legacy папкой, в которой хранятся все файлы из моего не-MVC проекта.

Мне нужно, чтобы Nginx сначала проверил, существует ли запрошенная страница / файл внутри прежней версии, если да, то я хочу использовать это. В противном случае я хочу вернуться к файлу index.php Laravel, который находится в project/public/.

Я не эксперт, когда дело доходит до конфигураций Nginx, поэтому любая помощь, которую вы можете предоставить, будет очень полезна.

1 Ответ

24 голосов
/ 21 июня 2012
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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...