2

I have the following config:

server {
  listen 80 default_server;

  access_log /var/www/logs/access.log;                                                                                           
  error_log /var/www/logs/error.log error;     

  root /var/www/web/;

  index index.html index.php;

  server_name _;

  location / { 
    try_files $uri $uri/ =404;
  }

  # HACK: This is temporary to work around renaming dozens of HTML links
  location ~ \.htm$ {
    root html;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.htm;

    include fastcgi_params;
  }
  # HACK: This is temporary to work around renaming dozens of HTML links

  location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
      return 404;
    }

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;

    include fastcgi_params;
  }
}

And I updated /etc/php5/fpm/pool.d/www.conf adding the line:

security.limit_extensions = .php .html 

Restarted FPM and NGINX but when I access .html files the PHP is not rendered...*.php files execute as expected...

What else am I missing???

3
  • I tried commenting out the PHP so it was JUST the html and that didn't work either?!? Commented Apr 22, 2016 at 18:34
  • Side note: your regex looks weird: .+?. This means "at least one token, which is optional". Either use .+ (at least one) or .* (zero or more). In this specific case of course you should use .+, since no file should start with .php. Commented Apr 23, 2016 at 9:47
  • You might need to restart the php-fpm process: systemctl restart php8.2-fpm (use your version number of course) Commented Mar 4, 2024 at 9:58

1 Answer 1

1

I would remove this:

    # HACK: This is temporary to work around renaming dozens of HTML links
  location ~ \.htm$ {
    root html;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.htm;

    include fastcgi_params;
  }

And use this instead:

location ~ \.(php|html|htm)$ {
   root           html;
   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_index  index.html;
   fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include        fastcgi_params;
}

I hope this solves your issue.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.