0

At my hosting control panel I set up my server api for server name (let it be dev.domainname.com).

dev.domainname.com config:

server {
        listen 80;
        #listen [::]:80;

        root /var/www/dev.domainname.com/public;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name dev.domainname.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

After I open dev.domainname.com brower receive a file called "download". Actually I checked that file - it is my index.php inside /public.

What's wrong?

Some additional info: I've installed SSL-certificate using certbot. https://dev.domainname.com isn't available too, I got ERR_CONNECTION_TIMED_OUT.

sudo tail -n 20 /var/log/nginx/error.log doesn't have any errors for the last hour.

hosts file contains one row:

127.0.0.1 domainname domainname

sudo nginx -t is also ok.

1 Answer 1

0

You need to tell nginx how to deal with php files. I create a "macro" which is simply a file containing the following:

location ~ \.php$ {
    fastcgi_param PHP_VALUE "display_errors=Off";
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include fastcgi.conf;
    fastcgi_send_timeout 600;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

I then store that in /etc/nginx/macros and include it with

include macros/php;
3
  • Can I change php 7.2 to 7.1 to make it work? Or there is other way for 7.1?
    – Tarasovych
    Aug 4, 2018 at 10:36
  • Now I have 502 Bad Gateway...
    – Tarasovych
    Aug 4, 2018 at 10:38
  • Yes php 7.1 works the same way. If you have bad gateway, are you sure you have php-fpm installed? Aug 4, 2018 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .