Question

Nginx Ubuntu 20.04 php files are downloading and not executing

The site runs Vue.JS as the root APP with a Django API

I’m wanting to run wordpress at mydomain.com/blog – as a sub folder

I have followed the DigitalOcean install document for PHP and MySQL (Nginx was already installed). Apache is not used and not installed

The site will server txt or HTML files eg https://mydomain.com/blog/readme.html but if I try to access https://mydomain.com/blog/test.php or https://mydomain.com/blog/index.php it just downloads and does not execute the php.

I have checked the nginx server blocks and tested php is loaded - and reloaded everything - rebooted server etc – but still no luck.

Here is my server block

server {
    server_name mydomain.com www.mydomain.com 123.456.789.123;

    root /var/www/html/vue/mydomain/dist;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        alias /home/mydomain/src;
    }

    location / {
        try_files $uri $uri/ /index.html /index.php;
    }

    location ^~ /rest-auth/ {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
    }

    location ^~ /api/ {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
    }

    location ~ /\.ht {
        deny all;
    }

   location ^~ /admin {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
    }

    location ^~ /blog {
      alias /var/www/html/blog;
      index index.php index.html index.htm;
      try_files $uri =404;
    }

# For security reasons, set php settings at root level.
# This prevents root level php files from showing as plain text.
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    error_log  /var/log/nginx/mydomain-error.log;
    access_log /var/log/nginx/mydomain-access.log;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name mydomain.com www.mydomain.com 123.456.789.123;
    return 404; # managed by Certbot
}

Thanks for any help it would be so appreciated – taken 6 hours so far and tried so many things and read lots of articles but nothing works – thank you.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @affyboy,

It’s possible this is an issue with your PHP-FPM config. Check it out, see if it’s working properly, you can configure it listen to a port and redirect the requests there just to make sure everything is being executed as expected.