Jeremy
Jeremy

Reputation: 2546

Nginx Configuration throws 500 Internal Server Error

According to 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:"

And below is the content of "/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;
    #}
}

When i do ls /var/run/ i don't see any php5-fpm.sock file (even though i have "sudo service php5-fpm start" or "sudo service php5-fpm restart"). I am not sure why is this happening.

I am relatively new with nginx, and currently experimenting nginx with magento. Basically am trying to install Magento using nginx.

When i browse to example.com, instead of seeing default magento installation i get "500 Internal Server Error" message.

The configuration above is based on multiple references:

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

and

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

Can anyone help me with this ? Thank you.

EDIT 1: I am using Ubuntu 14.04 (AWS EC2).

EDIT 2: enter image description here enter image description here enter image description here

EDIT 3: enter image description here

Upvotes: 0

Views: 4635

Answers (1)

Jehy
Jehy

Reputation: 4899

Just read your error log one more time. Nginx tries to communicate with php-fpm on socket unix:/var/run/php5-fpm.sock but it does not exist. This produces 500 internal error.

When i do ls /var/run/ i don't see any php5-fpm.sock file. I am not sure why is this happening.

You just need to set up php-fpm. At first, try running service php5-fpm restart and check if there are any errors. If there are some - fix them. Othervise, correct the path to socket.

Upvotes: 1

Related Questions