【发布时间】:2018-01-17 17:43:41
【问题描述】:
我想在 nginx ubuntu 16.04 服务器上部署简单的 laravel 应用。
我已将我的应用程序放入 /var/www/html 文件夹中
在我的服务器上,我已经设置了php 和mysql。
我在/etc/nginx/sites-enabled/myapp.com中添加了以下代码
server {
listen 80;
listen [::]:80;
root /var/www/html/MyApp/public;
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
server_name myapp.com;
error_log /var/log/nginx/myapp.com.log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
但不是运行应用程序,而是下载文件,所以我搜索并找到了stackoverflow链接:
Nginx serves .php files as downloads, instead of executing them
但这在我的情况下不起作用。
我对 nginx 不太了解,请帮帮我。
【问题讨论】:
-
您设置了
php或php-fpm吗? -
是的,我已经安装了 php 7.0.22
-
你需要
php-fpm,而不是php -
@Insax ,我已经安装了 php-fpm ,但现在显示 502 bad gateway
-
然后向我们展示一些来自 nginx 的错误日志
标签: laravel nginx deployment