【问题标题】:How To Deploy Laravel Application on Nginx Ubuntu 16.04 Server?如何在 Nginx Ubuntu 16.04 服务器上部署 Laravel 应用程序?
【发布时间】:2018-01-17 17:43:41
【问题描述】:

我想在 nginx ubuntu 16.04 服务器上部署简单的 laravel 应用。

我已将我的应用程序放入 /var/www/html 文件夹中

在我的服务器上,我已经设置了phpmysql

我在/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 不太了解,请帮帮我。

【问题讨论】:

  • 您设置了phpphp-fpm 吗?
  • 是的,我已经安装了 php 7.0.22
  • 你需要php-fpm,而不是php
  • @Insax ,我已经安装了 php-fpm ,但现在显示 502 bad gateway
  • 然后向我们展示一些来自 nginx 的错误日志

标签: laravel nginx deployment


【解决方案1】:

当 php-fpm 未运行或找不到套接字时,nginx 将显示错误 502 (bad gateway)。

在你的情况下,我认为问题出在这一行:

fastcgi_pass unix:/run/php/php7.0.22-fpm.sock;

试试改成

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

保存并重新加载或重启 nginx。

【讨论】:

  • 已经是fastcgi_pass unix:/run/php/php7.0-fpm.sock;在我的文件中
猜你喜欢
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
  • 2017-01-02
  • 1970-01-01
相关资源
最近更新 更多