nginx lädt PHP, aber nicht HTML

nginx lädt PHP, aber nicht HTML

also, zunächst einmal: ja, ich habe nach einer Lösung gesucht, aber ich kann sie nicht finden. Ich weiß, dass das Problem an meinem neu geschriebenen Code liegt, aber ich weiß nicht genug, um es zu beheben. Ich verwende nginx und php-fpm unter Debian 9.5.

PHP wird problemlos geladen, aber HTML funktioniert nicht mehr.

server {
    # SSL configuration
    #
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    root /var/www/example.com;

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

    server_name example.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri.php;
        rewrite ^(.*)$ $uri.php;
    }

    location /media {
        autoindex on;
        autoindex_exact_size off;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   #fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

Danke fürs Zuhören. Ich freue mich auf Ihre Antwort.

Bearbeiten: Nur zur Klarstellung: Ich möchte, dass in Python-Dateien die Erweiterung .php nicht in der URL angezeigt wird, dass HTML-Dateien jedoch normal geladen werden.

Antwort1

Diese Abteilung

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri.php;
    rewrite ^(.*)$ $uri.php;
}

sieht aus wie der Übeltäter. Die rewriteDirektive fängt einfach alle URIs ab und schreibt sie in eine .phpDatei um.

Bearbeiten gemäß Kommentaren

Basierend auf einer ähnlichen FrageHier, ich denke, was Sie brauchen, ist so etwas wie:

location / { 
    try_files $uri $uri/ @rules; 
} 

location @rules { 
    rewrite ^(.*)$ $1.php last;
}

verwandte Informationen