0

so, to start off with, yes, I have looked for a solution, but I can't find it. I know the issue is with my rewrite code, but I don't know enough to fix it. I'm using nginx and php-fpm on debian 9.5.

php loads just fine, but .html doesn't work anymore.

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;
    }
}

thanks for listening. I look forward to hearing back.

edit: just for clarification, my intention is for python files not to have the .php show in the url, but for html files to load normally.

Tomo-Nyan
  • 3
  • 2

1 Answers1

2

This section

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;
}

looks like the culprit. The rewrite directive simply catches all URIs and rewrites them to a .php file.

Edit as per comments

Based on a similar question here, I think what you need is something like:

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

location @rules { 
    rewrite ^(.*)$ $1.php last;
}
Daniele Santi
  • 2,529
  • 1
  • 25
  • 22