Nginx配置引发500内部服务器错误

时间:2016-05-10 09:46:01

标签: php magento nginx

根据error.log:

2016/05/10 16:48:27 [crit] 11638#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to client upstream, client: 123.456.789, server: example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"

以下是" / etc / nginx / sites-available / default"的内容:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    #root /usr/share/nginx/html;
    root /var/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name example.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.

        try_files $uri $uri/ /index.html;

        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location @handler{
        rewrite / /index.php;
    }

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

    location /images {
        root /usr/share;
        autoindex off;  
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass http://127.0.0.1:8080;    
    #}

    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/html;
        root /var/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;
    #   fastcgi SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #   include fastcgi_params;

        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

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

当我做ls / var / run /我没有看到任何php5-fpm.sock文件(即使我有" sudo服务php5-fpm start"或者" sudo服务php5-fpm restart")。我不确定为什么会这样。

我对nginx比较新,目前用magento试验nginx。基本上我正在尝试使用nginx安装Magento。

当我浏览到example.com时,我没有看到默认的magento安装,而是“内部服务器错误”#34;消息。

以上配置基于多个参考:

https://thomas-leister.de/linux/nginx-php-fpm-installieren-ubuntu-server/

https://www.howtoforge.de/anleitung/installation-von-nginx-mit-php5-und-php-fpm-mit-mysql-unterstutzung-unter-ubuntu-11-10/

任何人都可以帮我吗?谢谢。

编辑1: 我使用的是Ubuntu 14.04(AWS EC2)。

编辑2: enter image description here enter image description here enter image description here

编辑3: enter image description here

1 个答案:

答案 0 :(得分:1)

再次阅读您的错误日志。 Nginx试图在socket unix:/var/run/php5-fpm.sock上与php-fpm进行通信,但它不存在。这会产生500个内部错误。

  

当我执行ls / var / run / i时,我没有看到任何php5-fpm.sock文件。我不确定为什么会这样。

你只需要设置php-fpm。首先,尝试运行 service php5-fpm restart并检查是否有任何错误。如果有一些 - 修复它们。 Othervise,更正socket的路径。