I'm rather new to Nginx, but got it working w/ PHP5-FPM ... more or less.
What I want to do: Have Nginx call the PHP5-FPM parser for every PHP file located above the /var/www/example.com/ directory on the server. This sort of works, with one major flaw.
The http://example.com or https://example.com (with or without using i.e. index.php or test.php), the file just downloads as plain code. If I fiddle with the config a bit, I can get it to parse as plain text/html.
So it seems the PHP5-FPM parser isn't called for the url http(s)://example.com at all, while it seems to work as intended with http(s)://www.example.com
The issue seems rather nonsensical to me, but maybe there's something really obvious I've just missed - or that the NGinx PHP regexp is botched.
So, any tips/hints/recommendations would be much appreciated.
upstream php {
server unix:/var/run/example.com.socket;
}
server {
# none-SSL php/fastcgi
listen 80;
server_name example.com www.example.com;
access_log /var/log/nginx/example.com.access.log;
root /var/www/example.com/;
index index.php;
location ~ \.php$ {
fastcgi_pass php; #127.0.0.1:1025;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
return 301 https://www.example.com$request_uri; # Redirect to SSL
}
server {
# SSL php/fastcgi
server_name example.com www.example.com;
root /var/www/example.com/;
listen 443 ssl default_server;
index index.php;
ssl on; # Force SSL
ssl_certificate /etc/ssl/example.com/fullchain.pem; # cert.pem + chain.pem bundle
ssl_certificate_key /etc/ssl/example.com/privkey.pem;
access_log /var/log/nginx/example.com.log;
error_log /var/log/nginx/example.com.error.log;
location ~ \.php$ {
fastcgi_pass php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
}