Search code examples
nginxconfigurationvagrant

Change /var/www/html/ to /var/www/ because of 502 Bad Gateway


I've ran into an issue with an upgrade on php version in Vagrant. That is solved but my problem now is that what was working before isn't now and has to do with the directory where the local projects are – I presume.

I have the local projects (as before) in /var/www/ all the *.conf files in /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ are the same and pointing to the /var/www/.

The /etc/hosts file remains as before pointing, for instance 192.168.56.102 awesome.devel. This was working but not any more.

If I hit 192.168.56.102 on the browser it shoes me the Congratulations! You are pretty awesome. page which is located in /var/www/html/

My question is, where and how can I configure the server back to load the projects from /var/www/ and not from /var/www/html/ again, because it's there were all the projects are and all the *.conf files in sites-available and sites-enabled are configured.

Quick note: MariaDB is running fine, I can access the databases from Sequel Pro, I can ssh into vagrant, php running fine with PHP 7.1.17-1+ubuntu14.04.1+deb.sury.org+1 no problems here.

In my .conf files I have the following (just changes the project name):

server {
    listen *:80;

    server_name awesome.devel www.awesome.devel;
    client_max_body_size 1m;

    root /var/www/awesome/public/;
    index  index.html index.htm index.php;

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

    index index.php index.html index.htm;

    # static file 404's aren't logged and expires header is set to maximum age
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_pass   127.0.0.1:9000;
        try_files $uri $uri/ /index.php$is_args$args;
    }
}

Thanks in advance for any help


Solution

  • After the upgrade of php version, the config file for php has changed. The old php-fpm (version 5) was listening over tcp, but after upgrade php-fpm (version 7) is listening on the unix socket.

    But according to the nginx configuration given above, nginx is trying to connect to php-fpm over tcp, but php7 is configured to listen on unix socket.

    Changing the php config to listen over tcp will resolve the issue. The config in www.conf of php7 for the listen directive should be changed to the following

    listen = 127.0.0.1:9000