Ubuntu Nginx/Laravel 500内部服务器错误 [英] Ubuntu Nginx/Laravel 500 Internal Server Error

查看:129
本文介绍了Ubuntu Nginx/Laravel 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试访问时说:Http://localhost/page我从nginx收到500 Internal Server Error. 500 Internal Server Error nginx/1.1.19是页面上的全部状态.

When I try to access say: Http://localhost/page I get a 500 Internal Server Error from nginx. 500 Internal Server Error nginx/1.1.19 is all it states on the page.

在日志文件中,出现以下错误: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"

In the log file I get this error: 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"

编辑:我为laravel设置的路线似乎无效,这似乎是一个问题.因为最后一个错误意味着它正在对index.php进行重定向循环.我将try_files $uri $uri/ /index.html;更改为try_files $uri $uri/ =404;,现在它只显示404页.现在没有错误.

It looks like it is an issue with the Routes I set for laravel not taking effect. Because that last error means it is doing a redirect loop to index.php. I changed try_files $uri $uri/ /index.html; to try_files $uri $uri/ =404; and now it is just giving the 404 page. And now there is no error.

我暂时在本地服务器上使用LEMP堆栈,直到可以让Laravel Homestead与Vagrant和Oracle VM一起使用.我已经根据演练.

I am using a LEMP stack for my local server for the time being until I can get Laravel Homestead working with Vagrant and Oracle VM. I have set everything up according to this walkthrough.

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

Everything is working fine, I have nginx and php5 running fine. I was able to easily install php5-mcrypt so that composer would work, and the last thing I have done is change the root directory for nginx to be my project's public folder for Laravel. (So that our link calls could reference the root with / and work).

我的nginx.conf文件:

My nginx.conf File:

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/中的默认文件:

My default file in /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,但我又读了一遍,可能是问题所在.但是我可以根据需要将其更改回去.

In the nginx.conf file I set worker_processes to the default of 4, event though this is running on my laptop and I'm pretty sure I only have one processor. I had it set to 1, but I read on another through that that might be the issue. But I can change it back if needed.

推荐答案

所以我从更多的搜索中找到了答案.该页面最终使我得到答案: Laravel 4的nginx配置

So I found the answer from a little more searching around. This page ultimately lead me to the answer: nginx configuration for Laravel 4

我要做的是更改/etc/nginx/sites-available/中的默认配置,只需更改location / {}并添加location @rewrite.下面是我拥有的完整配置文件,其中大部分#注释行都列出来了.

What I had to do was change the default config in /etc/nginx/sites-available/ and just change location / {} and add location @rewrite. The full config file I have is below with most of the # commented lines out.

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;
    #}
}

这篇关于Ubuntu Nginx/Laravel 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆