0

I am running a VueJS system in the root of our site driven off a Django API on the same server.

example.com is a beta testing live version.

I am wanting to load wordpress into a subfolder example.com/blog

I am running Nginx [ no Apache - and Apache is NOT installed ].

Have installed PHP and MySQL and editing our server block. See code below.

I am getting 404 errors for any files I try to access in /blog eg

https://example.com/blog/readme.html 
https://example.com/blog/test.php 
https://example.com/blog/index.php 
https://example.com/blog/wp-admin/install.php

Here is our server block code {IP masked out}

server {
    server_name example.com www.example.com 128.199.###.###;

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

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

    location /static/ {
        alias /home/example/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;
      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/example-error.log;
    access_log /var/log/nginx/example-access.log;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.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.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


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


    listen 80;
    server_name example.com www.example.com 128.199.###.###;
    return 404; # managed by Certbot

}


Thank you kindly for any help -- I have looked through a lot of resources and tried a lot of things but no success - thank you.

David
  • 9
  • 1
  • 4
  • Does this help: https://stackoverflow.com/questions/12142172/apache-shows-php-code-instead-of-executing-it OR https://stackoverflow.com/questions/27565664/prompted-to-download-when-opening-php-files-in-firefox ? – Martin Apr 16 '21 at 14:02
  • Thanks @Martin you are great -- thanks for these -- I have not checked in Firefox -- just testing in chrome -- and in firefox I get a 404 ! -- So at least things are looking a bit better --- seems I have a link / path issue somewhere now – David Apr 16 '21 at 14:23
  • No worries! It is a central tenet of asking a new question on Stack Overflow to check first that a similar question has not already been asked, else you risk your question being closed as a duplicate. – Martin Apr 16 '21 at 14:38
  • I updated the question to reflect the current problem now that chrome was masking @Martin -- firefox shows a 404 error for the /blog links – David Apr 16 '21 at 14:40

1 Answers1

0

The chrome download issue masked a simple wrong path in the code ! Firefox showed a simple 404 which was easy to debug!

The final solution was to add this location for the blog :

location /blog {
          alias /var/www/html/blog;
          try_files $uri $uri/ @blog;

           location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_param SCRIPT_FILENAME $request_filename;
               fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            }
         }

     location @blog {
         rewrite /blog/(.*)$ /blog/index.php?/$1 last;
     }
David
  • 9
  • 1
  • 4