Deepin nginx lumen配置

正常安装

sudo apt install nginx
sudo apt install php-fpm

启动后将 /etc/nginx/sites-enabled/default 配置文件 copy一份到 /etc/nginx/conf.d/lumen_demo.conf

然后按照该配置文件改改,修改后的配置文件如下:

server {
listen 80;
listen [::]:80;

root ~/workspace/php/lumen/public;
index index.php;
server_name lumen_demo.com;
    error_log /var/log/nginx/lumne_demo_error.log;

location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}

完成,满心欢喜的访问

抱歉,404,下面是踩坑环节

踩坑开始

访问不到文件

在public文件夹下新建一个 test.html 文件,访问 lumen_test.com/test.html , 仍然404

是我哪里配错了?回到 defalt配置文件,将root修改为此文件夹,访问127.0.0.1//test.html, 404

修改路径为: /home/hujing/workspace/php/lumen/public, 可以访问

原来需要使用全路径,解决

满心欢喜,以为可以了,但是访问index.php会直接下载php文件

访问index.php直接下载

创建 b.php 文件,访问正常

添加路径参数修改:fastcgi_param SCRIPT_FILENAME $document_root/index.php;

正常访问

日志文件

期间查看日志文件:

nginx日志文件路径:/var/log/nginx/ (在nginx.conf中配置)

php-fpm 日志文件路径:/var/log/php7.0-fpm.log (在/etc/php/7.0/fpm/php-fpm.conf中配置)

最终配置文件如下

server {
listen 80;
listen [::]:80;
root /home/hujing/workspace/php/lumen/public;
server_name lumen_demo.com;
error_log /var/log/nginx/lumne_demo_error.log;
​  index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}

终于可以开心的开始lumen了,嘿嘿

原文地址:https://www.cnblogs.com/hujingnb/p/11666260.html