Ubuntu Nginx/Laravel 500 内部服务器错误

2024-03-13

当我尝试访问时说:Http://localhost/page我从 nginx 收到 500 内部服务器错误。500 Internal Server Error nginx/1.1.19就是页面上的全部内容。

在日志文件中我收到此错误:2014/07/06 17:56:32 [error] 2056#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: localhost, request: "GET /download HTTP/1.1", host: "localhost"

EDIT:看来是我为laravel设置的路由没有生效的问题。因为最后一个错误意味着它正在对 index.php 进行重定向循环。我变了try_files $uri $uri/ /index.html; to try_files $uri $uri/ =404;现在只是给出404页面。现在没有错误了。

我暂时在本地服务器上使用 LEMP 堆栈,直到我可以让 Laravel Homestead 与 Vagrant 和 Oracle VM 一起使用。我已经按照这个设置了一切演练 http://www.unixmen.com/install-lemp-server-nginx-mysql-mariadb-php-phpmyadmin-ubuntu-14-0413-10/.

一切工作正常,我的 nginx 和 php5 运行良好。我能够轻松安装 php5-mcrypt,以便 Composer 可以工作,我所做的最后一件事是将 nginx 的根目录更改为我的项目的 Laravel 公共文件夹。 (这样我们的链接调用就可以使用 / 引用根并起作用)。

我的 nginx.conf 文件:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml     application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

我在 /etc/nginx/sites-available/ 中的默认文件:

# server {
#   ...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www/DDbuddy/public;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #   # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#   listen 8000;
#   listen somename:8080;
#   server_name somename alias another.alias;
#   root html;
#   index index.html index.htm;
#
#   location / {
#       try_files $uri $uri/ /index.html;
#   }
#}


# HTTPS server
#
#server {
#   listen 443;
#   server_name localhost;
#
#   root html;
#   index index.html index.htm;
#
#   ssl on;
#   ssl_certificate cert.pem;
#   ssl_certificate_key cert.key;
#
#   ssl_session_timeout 5m;
#
#   ssl_protocols SSLv3 TLSv1;
#   ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
#   ssl_prefer_server_ciphers on;
#
#   location / {
#       try_files $uri $uri/ /index.html;
#   }
#}

在 nginx.conf 文件中,我将worker_processes 设置为默认值 4,尽管它在我的笔记本电脑上运行,而且我很确定我只有一个处理器。我将其设置为 1,但我在另一篇文章中读到这可能是问题所在。但如果需要的话我可以把它改回来。


所以我通过更多的搜索找到了答案。此页面最终引导我找到答案:Laravel 4 的 nginx 配置 https://stackoverflow.com/questions/21091405/nginx-configuration-for-laravel-4

我要做的就是更改默认配置/etc/nginx/sites-available/只是改变location / {}并添加location @rewrite。我拥有的完整配置文件如下,其中包含大部分内容#注释掉了行。

server {
    listen   80; ## listen for ipv4; this line is default and implied
    root /usr/share/nginx/www/DDbuddy/public;
    index index.php index.html index.htm;
    server_name localhost;

    location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }

    location / {
        try_files $uri $uri/ @rewrite;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Ubuntu Nginx/Laravel 500 内部服务器错误 的相关文章

随机推荐

  • 具有相同名称/路径的多个 cookie 的浏览器行为

    我对当存在多个具有相同名称和路径且对当前域有效的 cookie 时各种浏览器的行为感兴趣 例如 浏览器存储了这两个cookie key value path domain foo bar baz key value path domain
  • 为什么 svn import 选项无法检测文件重复

    如果我想签入 SVN 中已存在的同名文件 在这种情况下我将无法提交 例如 Name doc and name doc 但是 在这种情况下我将能够导入 这种情况甚至适用于文件夹名称 这可以防止将来进行结账操作 有没有办法防止文件或文件夹重复
  • 运行桌面版 libgdx 示例 gdx-invaders 时出现 java.lang.NoClassDefFoundError

    我正在构建 libgdx 的 gdx invaders 示例 有两个项目 gdx入侵者 基础项目 作为桌面 Java 应用程序运行gdx 入侵者 android项目 依赖于 gdx invaders 并作为 Android 应用程序运行 我
  • Golang反射:无法设置包装结构的接口字段

    我正在尝试实现一种方法 该方法可以更改可以具有任意结构的对象中的字段值 当我有指向结构的指针时 字段的遍历没有问题 但是 当我有一个接口不包装指向结构的指针而是包装结构本身时 我无法设法更改字段 简而言之 The following doe
  • 我什么时候必须声明 session_start(); ?

    所以我是 PHP 的初学者 所以我需要一些帮助 我正在尝试确定何时开始会议 我应该在用户首次注册时执行此操作还是在用户登录时执行此操作 另外 会话是否 通用 意味着当我检查会话时它会起作用还是我必须在所有页面中包含一个文件来检查某人是否有会
  • .NET 中的 DDD / 聚合

    我一直在阅读 Evans 关于 DDD 的书 并且正在思考应该如何在 NET 中实现聚合 目前 我只能想出一种方法 将聚合隔离在单独的类库中 然而 这似乎有点矫枉过正 我更愿意将所有域对象保留在一个库中 我想知道是否有不同的方法 1 lib
  • 使用 Criteria API 从 NHibernate 获取不同的结果集?

    我试图使用 NHibernate 中的 Criteria API 获得不同的结果 我知道使用 HQL 可以做到这一点 但我更喜欢使用 Criteria API 来执行此操作 因为我的应用程序的其余部分仅使用此方法编写 我找到这个论坛帖子 h
  • 使用 NEON 对 ARM 汇编中的四字向量中的所有元素求和

    我对组装相当陌生 尽管手臂信息中心通常很有帮助 但有时这些说明可能会让新手感到有点困惑 基本上我需要做的就是对四字寄存器中的 4 个浮点值求和 并将结果存储在单个精度寄存器中 我认为 VPADD 指令可以满足我的需要 但我不太确定 你可以尝
  • 如何从NLP Tree中提取元素?

    我正在使用NLP包来解析句子 我怎样才能从Tree创建的输出 例如 我想抓住名词短语 NP 来自下面的示例 library NLP library openNLP s lt c Really I like chocolate because
  • 在所有页面中正确包含 php 标头

    我会包含一个 php 标头 mysite com header php 在站点的所有页面中 怎样做才正确呢 有相关链接 这没有帮助 你可以这样做 include SERVER DOCUMENT ROOT header php
  • 侦听大多数端口时出现 Node.js EACCES 错误

    我正在测试一个应用程序 希望在heroku 上运行 但在本地也遇到问题 当它运行 http Server listen 时 它给我一个 EACCES 错误 但它只发生在某些端口上 所以 我在本地运行 joe joebuntu node gt
  • 尝试编写 C++ 包装函数时,无法在 Cython 中将 Numpy 数组转换为 OpenCV Mat

    我正在尝试实施cv cuda warpPerspective在 python2 中 有一篇关于如何做到这一点的非常精彩的文章 link https stackoverflow com a 42401559 7555390 我按照该帖子中描述
  • Jquery - 调暗整个页面并淡出一个 div 元素

    我正在尝试执行以下操作 单击链接会触发一个功能 该功能将显示一个 DIV page cover 使整个背景变暗 该 div 的 z 索引为 999 然后我想要另一个 div red 出现在暗淡的背景 淡出 显示上 并具有更高的 z inde
  • 如何使用 git 存储库跨项目组织共享代码/资产

    我有一个场景 其中基础项目由java代码和网站文件 jsp html javascript 模板 css 图像等 组成 创建此基础项目的变体的原因如下 a 白标 定制 b 基于此项目的新项目 但有附加功能 在 java 和 web 文件中
  • npm 已弃用警告 – 我需要更新某些内容吗?

    做完之后npm install为了获取项目的依赖项 我经常收到很多这样的消息 npm WARN deprecated email protected cdn cgi l email protection lodash lt 2 0 0 is
  • 多对多关联表上的 SQLAlchemy 关系

    我正在尝试建立与另一个多对多关系的关系 代码如下所示 from sqlalchemy import Column Integer ForeignKey Table ForeignKeyConstraint create engine fro
  • 构造函数技巧

    我认为这是不可能的 但我想在放弃之前问你一下 我想要类似 constexpr 增量的东西 include
  • PyCharm Django 上一个项目的服务器在打开并运行另一个项目后仍然运行

    重现问题的步骤 打开第一个项目 py 管理 py 运行服务器 现在我可以通过地址在浏览器中看到我的 Project 1 网站http 127 0 0 1 8000 http 127 0 0 1 8000 在 PyCharm 中关闭项目并打开
  • 强力查询中的匹配列表/表

    我认为这必须有一个简单的答案 但我找不到任何例子 我必须将列表的每个成员与子字符串列表进行比较 以查看该成员是否包含子字符串 如果包含 则将该子字符串返回到与第一个列表的成员位于同一位置的第三个列表 Example ListA help m
  • Ubuntu Nginx/Laravel 500 内部服务器错误

    当我尝试访问时说 Http localhost page我从 nginx 收到 500 内部服务器错误 500 Internal Server Error nginx 1 1 19就是页面上的全部内容 在日志文件中我收到此错误 2014 0