我想在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;
}
}
但是它不是运行应用程序,而是在下载文件,所以我搜索并找到了堆栈溢出链接:
Nginx将.php文件作为下载提供,而不是执行它们
但这在我的情况下不起作用.
我对nginx没有太多想法,请帮助我。
>nginx将在php-FPM未运行或找不到套接字时显示错误502(错误的网关(。
在您的情况下,我认为问题出在这一行:
fastcgi_pass unix:/run/php/php7.0.22-fpm.sock;
尝试将其更改为
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
保存并重新加载或重新启动nginx。