【问题标题】:laravel project with nginx errors带有 nginx 错误的 laravel 项目
【发布时间】:2018-07-11 06:10:15
【问题描述】:

我已经将我的 laravel 项目上传到远程 linux 主机。这个项目在我本地的 windows homestead 上运行良好。但是当我把它放在 linux 主机上时,它不起作用。 项目根目录是 :/var/www/html/blog 。 nginx 配置如下:

`server
    {
        listen 80;
        #listen [::]:80;
        server_name www.antichina.us ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /var/www/html/blog/public;

       # include other.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }



        access_log off;
    }
`

当我使用域访问项目时,(http://mydomain),it 给出http 500 错误。但是当我在nginx 配置文件中将root 设置为/var/www/html/blog 时,项目的索引页是访问:http://mydomain/public,其他路由都返回404错误。

我已经尝试了我的方法,但似乎没有一个有效。任何可以帮助我吗?谢谢!

【问题讨论】:

  • 你的标题说有错误,但你没有说是什么。
  • 当我使用域访问项目时,(mydomain),it 给出 http 500 错误。但是当我在 nginx 配置文件中将根设置为 /var/www/html/blog 时,索引项目页面正在工作,访问:mydomain/public,其他路由都返回404错误。

标签: laravel nginx


【解决方案1】:

将此添加到您的 nginx 配置中

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

您的索引行也只需要这样做:

index index.php;

这个文件里有什么?

include enable-php.conf;

【讨论】:

  • 在 enable-php.conf 文件中:location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }
  • 您确定您使用的是fastcgi 而不是php-fpm
  • 其实我对nginx的配置知之甚少。
  • 你可以访问linux主机命令行吗?如果是这样,请键入 ps aux | grep php-fpm。您应该会看到类似 1 root php-fpm master process 的内容。
  • 根 962 0.0 0.4 151436 4892 ? Ss 15:48 0:00 php-fpm: 主进程 (/usr/local/php/etc/php-fpm.conf) www 963 0.0 0.4 151436 4300 ? S 15:48 0:00 php-fpm: 池 www www 964 0.0 0.4 151436 4296 ? S 15:48 0:00 php-fpm:池 www root 981 0.0 0.0 6380 700 pts/1 S+ 16:08 0:00 grep php-fpm
猜你喜欢
  • 2020-05-07
  • 2020-06-15
  • 2020-11-12
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
  • 2019-05-16
  • 1970-01-01
相关资源
最近更新 更多