【发布时间】:2019-02-05 22:36:06
【问题描述】:
已解决 嗨,我正在将我的第一个 Laravel 应用程序部署到 DigitalOcean,尝试访问 url 时出现 500 错误。首先让我说这是我的第一次 Laravel 和 Nginx 部署,也是我第一次配置 Web 服务器,所以如果你发现有问题,我欢迎反馈!我知道我可以使用 Forge,但我正在努力学习,所以请耐心等待。
服务器由以下部分组成:
- Ubuntu 18.04
- Nginx 1.14.0
- PHP 7.2.7
- Laravel 5.6
这是我的 Nginx 配置文件(出于安全原因,我将 SSL 路径更改为 path_to 并将我的 url 更改为 sub.domain.com):
server {
listen 80;
root /var/www/sub.domain.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.php$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
listen 443 ssl; # managed by Certbot
ssl_certificate /path_to/sub.domain.com/fchain.pem$
ssl_certificate_key /path_to/sub.domain.com/pkey.p$
include /path_to/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /path_to/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.sub.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = sub.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name sub.domain.com www.sub.domain.com;
return 404; # managed by Certbot
}
我的本地主机上有一个存储文件夹,其中包含指向 public/storage 的符号链接。我在 storage/app/public 中有几个文件夹,但是当我将项目克隆到服务器时,这些文件夹都没有传输过来,并且符号链接似乎丢失了,因为公共文件夹中没有存储文件夹。所以我跑了php artisan storage:link,现在我有了公共/存储。我假设我只需要重新创建 storage/app/public 中的目录。
当我尝试访问我的 url 时出现 500 错误,这是来自 Nginx 的错误:
*111 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught ErrorException: file_put_contents(/var/www/sub.domain.com/storage/framework/views/7315ddb3840f197f8140b159965a4ba4b98e33fe.php): failed to open stream: Permission denied in /var/www/sub.domain.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
经过一番研究,我发现一篇文章说我需要更改存储文件夹的权限,所以我运行了以下两个命令:
sudo chmod -R o+w storage/
sudo chmod -R 775 storage/
很遗憾,这并没有解决我的问题。它还提到更改引导文件的权限,但我不确定这是指什么。我不确定这是否是我的 Nginx 配置文件的问题(我已多次更改)或者是否是权限问题。由于我遇到的错误,我猜这是权限问题。
感谢您的帮助!谢谢!
【问题讨论】:
标签: nginx laravel-5.6 ubuntu-18.04 php-7.2