Subdomains nginx

May 10, 2014 2.4k views
Hello! When i load my subdomain.site.com browser asks whether to save the file? Nginx subdomain conf ~~~~ server { listen 80; server_name test.site.com; root /usr/share/nginx/www/test; index index.php index.html; location / { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ~~~~ This conf works great for non php files(e.g. index.html) What i need to do?
3 Answers
Hi, this is a solution for you:

server {
listen 80;
server_name test.*;
charset utf-8;

location / {
root /usr/share/nginx/www/test;
index index.html index.htm index.php;

location ~ \.php$ {
try_files $uri = 404;
root /usr/share/nginx/www/test;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME
$document_root $fastcgi_script_name;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;

Leandro Naves
Hello! Thanks for answer. When i restart nginx its failed with error

invalid parameter "$fastcgi_script_name"
@Evgenity: Make sure that part is all on one line:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Have another answer? Share your knowledge.