Welcome! Log In Create A New Profile

Advanced

php inside .shtml using Nginx?

Posted by sh4ka 
php inside .shtml using Nginx?
February 13, 2013 06:38AM
Hello everybody,

Time ago, when I used apache web server, to parse php files inside a .shtml (SSI), the only thing I had to do was to put this content, inside a .htaccess:

Code:
AddType application/x-httpd-php .shtml

It was fine using Apache. However now I'm using Nginx with php-fpm and I've enabled SSI module, using this:

Code:
location / {
ssi on;
ssi_silent_errors off;
...
}

ssi works perfect using this for example:

Code:
<!--# set var="test" value="Hello nginx!" -->
<!--# echo var="test" -->
However, I need to parse PHP code inside the SHTML file, like this:

Code:
<?php
echo "This is php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Site</title>
</head>

<body>

<div style="margin-top:200px;" align="center">
<img src="logo.jpg" width="600" height="182" />
</div>
</body>
</html>
And all I got at the browser is a blank page, with no errors at the logs.

This is the virtual host config I'm using:

Code:
### mysite.com

server {
access_log off;
error_log /var/log/nginx/error.log;
listen 80;

server_name mysite.com www.mysite.com;

location ~* \.(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf|html)$ {

root /var/www/sites/mysite.com;

expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}


location / {
ssi on;
ssi_silent_errors off;

root /var/www/sites/mysite.com;
index index.shtml index.php index.html index.htm;


# rewrites over here.


}

# php parsed using php-fpm daemon
location ~ \.php$ {
root /var/www/sites/mysite.com;
try_files $uri =404;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}


}

Any help? What am I missing?

Thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 93
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready