dongsigan2044 2018-10-16 05:28
浏览 100

Laravel变换路径上下文

I have Laravel(5.7) project and will be deployed to a server (nginx) with multiple projects. I am running the project in my Local machine using Apache and I tried to run it with subdirectory and it is working in my machine.

We have a problem in deployment of my project in subdirectory of the server (nginx), I don't know if the Laravel project has the problem because everytime we go to the http://172.1.1.1/sample of my project it always show the "404 Page not found" of Laravel because Laravel thought that /sample is a path so I think 172.1.1.1/sample runs the Laravel but it didn't make /sample as it's root but when we go to 172.1.1.1 the other project running here is working. What I already did is add the following code in my Laravel project.

In my AppServiceProvider.php - I add the following code:

public function boot()
{

       \URL::forceRootUrl(\Config::get('app.url'));   

        if (str_contains(\Config::get('app.url'), 'https://')) {
            \URL::forceScheme('https');
            //use \URL:forceSchema('https') if you use laravel < 5.4
        }
    }

So that when I change the APP_URL in .env of my project, it will work.

APP_URL=http://localhost:9021/sample

And add the following in the .htaccess of my public folder:

RewriteEngine On
RewriteBase /sample/

So it is working for my local machine but this doesn't work when we tried to deploy this. Once we go to 172.1.1.1/sample (sample-ip) it will just show the "404 Page not found".

What I want to know is if there are other way to change the context path of laravel 5.7. Because I am not the one who configure the nginx in the server but I want to make sure that the problem is not because of Laravel 5.7.

Thank you for your help guys.

  • 写回答

1条回答 默认 最新

  • dongluo1853 2018-10-16 06:06
    关注

    see this documentation

    laravel with nginx

    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容