2014-07-06 135 views
3

当我尝试访问说:Http://localhost/page我从nginx得到一个500内部服务器错误。它在页面上全部显示为500 Internal Server Error nginx/1.1.19Ubuntu Nginx/Laravel 500内部服务器错误

在日志文件中我得到这个错误: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页面。现在没有错误。

我正在为本地服务器使用LEMP堆栈,直到我可以让Laravel Homestead与Vagrant和Oracle VM合作。我已经根据这个walkthrough设置了一切。

一切工作正常,我有nginx和php5运行良好。我能够轻松安装php5-mcrypt,以便作曲家能够工作,而我所做的最后一件事就是将nginx的根目录更改为Laravel的项目公用文件夹。 (以便我们的链接调用可以通过/和work来引用root)。

我的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的/网站可用/:

# 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文件I设置worker_processes为默认4,事件虽然这是在我的笔记本上运行,我敢肯定,我只有一个处理器。我已将它设置为1,但我通过阅读另一个可能是问题的方式来阅读另一个。但如果需要,我可以将其更改回来。

+0

你检查了日志吗? – lagbox

+0

'2014/07/06 17:56:32 [error] 2056#0:* 2在内部重定向到“/index.html”时,重写或内部重定向周期,客户端:127.0.0.1,server:localhost,request:“ GET /下载HTTP/1.1“,主机:”localhost“'这是它显示的错误(我将添加到帖子) –

回答

0

所以我找到了更多的搜索周围的答案。此页面最终导致我的回答: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; 
    #} 
}