【问题标题】:Laravel site works in directory, but isn't opened when move to subdirectory in Ubuntu 16.04Laravel 站点在目录中工作,但在 Ubuntu 16.04 中移动到子目录时未打开
【发布时间】:2017-11-06 07:13:02
【问题描述】:

我使用的是 Ubuntu 16.04。这是我的虚拟主机配置。我从

编辑了我的根文件夹

/var/www/example.com/public_html/mysite/public

/var/www/example.com/public_html

然后我为子目录配置了我的 vitualhost,如下所示。网站只显示白屏。错误日志,nginx错误日志为空。

server {
        listen 80;
        #listen [::]:80 default_server ipv6only=on;

    root /var/www/example.com/public_html;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    error_log /var/www/logs/error.log;

   location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }

    location ^~ /mysite {

            alias /var/www/example.com/public_html/mysite/public;
            try_files $uri $uri/ @mysite;

            location ~* \.php {
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                include /etc/nginx/fastcgi_params;
            }
    }

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

}

我不知道是什么问题。

1) 文件权限,laravel 配置已正确完成。

2) 我认为问题出在 php fpm。但它可以,打开没有子目录的网站

我之前在 Ubuntu 14.04 中做过同样的事情。看来,在 Ubuntu 16.04 中存在一些差异。另外,我检查了我的 public/index.php,在那里添加了 die() 函数和消息。但是,又是白屏。也许,我在配置 Nginx 时错过了什么?

【问题讨论】:

    标签: ubuntu nginx laravel-5


    【解决方案1】:

    /public 是 laravel 的子目录,当你将项目移动到另一个目录时,root 应该是your_project_path/public

    【讨论】:

    • 同样的事情。在我的 public_html 中有多个站点为mySitemySecondSitepublicmySitemySecondSite 内。这是 Laravel 的索引文件夹。
    • 文档根目录应该是 path_to_public_html/mySite/public
    • 我只想通过mysite.com/mysite 访问该网站。 mysite.com 不应该打开子目录。
    • 你重启你的nginx服务器了吗?
    • 是的。正如我所说,我在 Ubuntu 14.04 中进行了相同的配置。但是不知道为什么会显示白屏?
    猜你喜欢
    • 2014-06-13
    • 2017-05-06
    • 2018-08-22
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多