1

I am relatively new to NGINX, I admit (less than 24 hours), but, I got it basically configured. I'm setting up a site for a friend, and I saw an example of some code that uses subdomains like in the code below. But, in the subdomain, PHP won't work. It just asks me to download the file if I go to "subdomain.domain.tld", but, if I go to "subdomain.domain.tld/index.php", it says "No input file specified." The subdomain is phpmyadmin, by the way.

server {
    listen    80;
    server_name   irc.physibots.info;

    rewrite (.*)       http://physibots.info:3989;
}

server {
    listen 80;
    server_name "~^([a-z]+)?.physibots.info";

    root /home/virtual/physibots.info/subdomains/$1;
    index index.php index.html index.html;

    location / {
      autoindex on;
    }
    location ~ \.php {
        try_files $uri /error.html
        fastcgi_index index.php;
        fastcgi_pass unix:/tmp/php.socket;

        include fastcgi_params;
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

#server {
#    listen         443;
#    server_name    localhost;
#
#    charset utf-8;
#
#    ssl on;
#    ssl_certificate

server {
    listen        80;
    server_name   physibots.info default;

    root          /home/virtual/physibots.info/public_html;
        index index.php index.html index.html;

    location / {
        autoindex on;
    }
    location ~ \.php {
        try_files $uri /error.html
        fastcgi_index index.php;
        fastcgi_pass unix:/tmp/php.socket;

        include fastcgi_params;
            fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
1
  • Did you try to access a static file as well, from the same subdomain? If the static file is served well, the problem is in the fastcgi config, if not, it's in the nginx config, that would be good to know :) Nov 15, 2011 at 9:26

1 Answer 1

2

Move the try_files to your location / { } block and change it to try_files $uri $uri/ /index.php;

    location / {
        autoindex on;
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php {
        fastcgi_index index.php;
        fastcgi_pass unix:/tmp/php.socket;

The rest looks surprisingly good for a beginner. :)

Also- make sure you're testing with curl and not a web browser or you'll constantly fight caching.

1
  • THANKS!, I had a complete different issue, but the caching was my problem all along! :) Oh my issue was that my PHP files were being downloaded. I had solved the issue, but because the browser was caching, it kept downloading the PHP files. Thanks a lot! Jun 9, 2013 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.