Bryan
Bryan

Reputation: 55

nginx 404 Not Found for php files

I'm trying to setup PHP on Nginx. My Nginx is already configured for a Django website. The subdirectory /wiki will run php powered software.

server {
    server_name = my_domain_name.com;

    # django stuff here

    location/wiki {
        alias /var/www/mediawiki;
        try_files $uri =404;
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # i have verified that this does exist on my system
    }

    location ~ /\.ht {
        deny all;
    }

    # more django and certbot stuff

With this configuration, my_domain_name.com/wiki/index.html can be accessed, but my_domain_name.com/wiki/info.php yields a 404 Not Found nginx page. Yet, they both reside in /var/www/mediawiki. What is wrong with my configuration?

Upvotes: 1

Views: 1969

Answers (1)

Bryan
Bryan

Reputation: 55

Per Richard Smith's reference, I figured out that I needed to include a nested location php tag:

location/wiki {
    alias /var/www/mediawiki;
    try_files $uri =404;
    index index.html index.htm index.php;

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

and php files are served now.

Upvotes: 2

Related Questions